Skip to content

Commit

Permalink
Avoid thread profiling functions completely when not enabled (#15677)
Browse files Browse the repository at this point in the history
Previously we were imports JS stubs for the profiling functions
even in release builds, which was increasing the code size
of all threaded programs.
  • Loading branch information
sbc100 authored Dec 1, 2021
1 parent 8ce0ce0 commit faf4790
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,8 @@ def phase_linker_setup(options, state, newargs, settings_map):
settings.MEMORYPROFILER = 1

if settings.PTHREADS_PROFILING:
if not settings.ASSERTIONS:
exit_with_error('PTHREADS_PROFILING only works with ASSERTIONS enabled')
options.post_js.append(utils.path_from_root('src/threadprofiler.js'))

options.pre_js = read_js_files(options.pre_js)
Expand Down
4 changes: 2 additions & 2 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,7 @@ var LibraryPThread = {
#endif
},

// The profiler setters are defined twice, here in asm.js so that they can be #if'ed out
// without having to pay the impact of a FFI transition for a no-op in non-profiling builds.
#if ASSERTIONS
emscripten_conditional_set_current_thread_status__sig: 'vii',
emscripten_conditional_set_current_thread_status: function(expectedStatus, newStatus) {
#if PTHREADS_PROFILING
Expand All @@ -1058,6 +1057,7 @@ var LibraryPThread = {
PThread.setThreadName(threadId, UTF8ToString(name));
#endif
},
#endif

// This function is call by a pthread to signal that exit() was called and
// that the entire process should exit.
Expand Down
6 changes: 6 additions & 0 deletions system/include/emscripten/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ void emscripten_thread_sleep(double msecs);
#define EM_THREAD_STATUS_FINISHED 6
#define EM_THREAD_STATUS_NUMFIELDS 7

#ifdef NDEBUG
#define emscripten_set_current_thread_status(newStatus)
#define emscripten_conditional_set_current_thread_status(expectedStatus, newStatus)
#define emscripten_set_thread_name(threadId, name)
#else
// Sets the profiler status of the calling thread. This is a no-op if thread
// profiling is not active.
// This is an internal function and generally not intended for user code.
Expand All @@ -332,6 +337,7 @@ void emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS expectedS
// When thread profiler is not enabled (not building with --threadprofiler),
// this is a no-op.
void emscripten_set_thread_name(pthread_t threadId, const char *name);
#endif

// Gets the stored pointer to a string representing the canvases to transfer to
// the created thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ I
J
K
L
M
N
O
r
s
t
u
v
w
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ a.n
a.o
a.p
a.q
a.r
a.s
a.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ n
o
p
q
r
s
t
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16909
16826

0 comments on commit faf4790

Please sign in to comment.