From b84ef4d67eaf9f9fd7fd700ca05339cb0cdff742 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 25 Jul 2024 10:51:16 +0200 Subject: [PATCH] Adapt comphelper::ThreadPool to Emscripten's threading needs ...by keeping the worker threads around by default instead of joining and later re-spawning them; see 5b1df7709d75c6dd993da5a272e7e37e55a70174 "Document the Emscripten threads issue". But lets be cautious and change the bJoin default only for Emscripten. Also, cap the thread pool size to MAX_CONCURRENCY=4 and increase to -sPTHREAD_POOL_SIZE=6. In an experimental setup where the Emscripten build starts up with the start center rather than a Writer document, that is just enough to cover the thread-spawning needs when executing the start center window's paint task: Four threads for the comphelper::ThreadPool (used from within drawinglayer::convertToBitmapEx -> ... -> BitmapBasicMorphologyFilter::filter), and one each for configmgr::Components::WriteThread (see e8358d0a0f7c2c4b1ccf800fe9ec8a7f2bf7066a "Keep around a single configmgr::Components::WriteThread instance") and salhelper::TimerManager. Change-Id: I5b1d0e9dc09f05fb3b679c8dc1c38ee45c61c0f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171004 Reviewed-by: Stephan Bergmann Tested-by: Jenkins --- include/comphelper/threadpool.hxx | 8 +++++++- solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk | 2 +- static/emscripten/environment.js | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx index 84f9dc9284f6..0b2ebc8ac9e6 100644 --- a/include/comphelper/threadpool.hxx +++ b/include/comphelper/threadpool.hxx @@ -67,7 +67,13 @@ public: /** Wait until all queued tasks associated with the tag are completed @param bJoin - if set call joinThreadsIfIdle() at the end */ - void waitUntilDone(const std::shared_ptr&, bool bJoin = true); + void waitUntilDone(const std::shared_ptr&, bool bJoin = +#if defined EMSCRIPTEN + false +#else + true +#endif + ); /// join all threads if there are no tasks presently. void joinThreadsIfIdle(); diff --git a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk index 45beedd1af34..3898ead4448d 100644 --- a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk +++ b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk @@ -15,7 +15,7 @@ gb_EMSCRIPTEN_CPPFLAGS := -pthread -s USE_PTHREADS=1 -D_LARGEFILE64_SOURCE -D_LA gb_EMSCRIPTEN_LDFLAGS := $(gb_EMSCRIPTEN_CPPFLAGS) # Initial memory size and worker thread pool -gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=4 +gb_EMSCRIPTEN_LDFLAGS += -s TOTAL_MEMORY=1GB -s PTHREAD_POOL_SIZE=6 # To keep the link time (and memory) down, prevent all rewriting options from wasm-emscripten-finalize # See emscripten.py, finalize_wasm, modify_wasm = True diff --git a/static/emscripten/environment.js b/static/emscripten/environment.js index 5ad1f41363ed..4e5d1f98c596 100644 --- a/static/emscripten/environment.js +++ b/static/emscripten/environment.js @@ -2,5 +2,6 @@ if (!('preRun' in Module)) Module['preRun'] = []; Module.preRun.push(function() { + ENV.MAX_CONCURRENCY = '4'; ENV.SAL_LOG = "+WARN" });