Run Emscripten RestClient fetches on a worker thread - #409
Merged
Conversation
drslebedev
marked this pull request as draft
August 21, 2026 10:24
drslebedev
force-pushed
the
fetch_work_thread
branch
2 times, most recently
from
August 21, 2026 10:42
15c7ed1 to
b49f7bf
Compare
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 21, 2026 13:29 — with
GitHub Actions
Inactive
drslebedev
force-pushed
the
fetch_work_thread
branch
from
August 24, 2026 09:22
b49f7bf to
4978c36
Compare
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:23 — with
GitHub Actions
Inactive
drslebedev
force-pushed
the
fetch_work_thread
branch
from
August 24, 2026 09:31
4978c36 to
c67b2d1
Compare
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 09:31 — with
GitHub Actions
Inactive
Emscripten delivers fetch callbacks on the thread that issued the request, after that thread returns to the JS event loop. ClientContext worked around this by starting a std::thread for every command and immediately joining it, blocking its poller. Direct RestClient users such as OpenDigitizer had no workaround, so fetch callbacks could run on the browser main thread. Give each Emscripten RestClient a persistent worker and route requests, long polling, unsubscribe and cleanup through it. Resume a 504 long-poll timeout at the same index instead of ending the subscription. Fetch completion and subscription callbacks now run on the REST worker, so consumers must synchronise shared state. Each active client uses one worker, which is reclaimed asynchronously during shutdown. Remove the per-request thread workaround from ClientContext. The native RestClient implementation is unchanged. Add an Emscripten integration test covering subscriptions, unsubscribe, shutdown, callback threading and worker reclamation. The Node test requires the xhr2 npm package. Browser tests are registered when emrun and a matching browser are available; OPENCMW_REQUIRE_BROWSER_TESTS requires at least one browser test. Signed-off-by: drslebedev <dr.s.lebedev@gmail.com>
drslebedev
force-pushed
the
fetch_work_thread
branch
from
August 24, 2026 10:38
c67b2d1 to
bc214ed
Compare
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:38 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:39 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:39 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:39 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:39 — with
GitHub Actions
Inactive
drslebedev
temporarily deployed
to
configure coverage
August 24, 2026 10:39 — with
GitHub Actions
Inactive
|
drslebedev
marked this pull request as ready for review
August 24, 2026 12:53
RalphSteinhagen
approved these changes
Aug 24, 2026
RalphSteinhagen
left a comment
Member
There was a problem hiding this comment.
Great addition to the unit-test suites and thanks a lot for the WASM-worker changes of the REST Clients. That should resolve a lot of the CPU and network contention, eliminate dropping of data in high network load conditions, and alleviate the CPU performance issues.
The data point reduction algorithm you indicated would be a further improvement but I'd rather de-prioritize this in favour of tackling the issue at the source (i.e. ImPlot/ImGUI itself).
RalphSteinhagen
pushed a commit
to fair-acc/opendigitizer
that referenced
this pull request
Aug 26, 2026
* Bump OpenCMW for fair-acc/opencmw-cpp#409 * Bump gr-digitizers for fair-acc/gr-digitizers#207 Update OpenDigitizer to: - use canonical gr:: tag keys throughout the service and UI - propagate canonical trigger metadata from remote sources - interpret trigger offsets in seconds - handle canonical dropped-sample tags Signed-off-by: drslebedev <dr.s.lebedev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Emscripten delivers fetch callbacks on the thread that issued the request,
after that thread returns to the JS event loop. ClientContext worked around
this by starting a std::thread for every command and immediately joining it,
blocking its poller. Direct RestClient users such as OpenDigitizer had no
workaround, so fetch callbacks could run on the browser main thread.
Give each Emscripten RestClient a persistent worker and route requests, long
polling, unsubscribe and cleanup through it. Resume a 504 long-poll timeout
at the same index instead of ending the subscription.
Fetch completion and subscription callbacks now run on the REST worker, so
consumers must synchronise shared state. Each active client uses one worker,
which is reclaimed asynchronously during shutdown.
Remove the per-request thread workaround from ClientContext. The native
RestClient implementation is unchanged.
Add an Emscripten integration test covering subscriptions, unsubscribe,
shutdown, callback threading and worker reclamation. The Node test requires
the xhr2 npm package. Browser tests are registered when emrun and a matching
browser are available; OPENCMW_REQUIRE_BROWSER_TESTS requires at least one
browser test.