Rebase browser port onto upstream, restore threaded build (#38) - #41
Open
thomasballinger wants to merge 1 commit into
Open
Rebase browser port onto upstream, restore threaded build (#38)#41thomasballinger wants to merge 1 commit into
thomasballinger wants to merge 1 commit into
Conversation
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 22:26 — with
GitHub Actions
Inactive
thomasballinger
force-pushed
the
threads
branch
from
August 8, 2026 22:52
7b41715 to
ac6817e
Compare
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 22:52 — with
GitHub Actions
Inactive
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 22:52 — with
GitHub Actions
Inactive
thomasballinger
force-pushed
the
threads
branch
from
August 8, 2026 23:00
ac6817e to
f0687f9
Compare
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:00 — with
GitHub Actions
Inactive
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:00 — with
GitHub Actions
Inactive
thomasballinger
force-pushed
the
threads
branch
from
August 8, 2026 23:03
f0687f9 to
45c1d8c
Compare
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:03 — with
GitHub Actions
Inactive
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:03 — with
GitHub Actions
Inactive
Emscripten supports pthreads, and Endless Sky's TaskQueue drives both sprite
loading and the Engine's per-frame calculation step, so running single-threaded
costs both startup time and frame pacing under load. Turning threads on removes
every Emscripten-specific workaround from TaskQueue.cpp and Audio.cpp -- their
diff against upstream drops to zero.
- Makefile: -pthread in COMMON_FLAGS, -s PTHREAD_POOL_SIZE=10
- endless-sky.html: pass --tq-threads N to callMain, using a flag upstream
already has (main.cpp -> TaskQueue::SetWorkerThreadCount). Upstream sizes its
pool from hardware_concurrency(), which in a browser can exceed
PTHREAD_POOL_SIZE; overflowing it makes Emscripten create threads on demand,
which needs the main thread to reach the event loop -- and it may be blocked
in the game loop when that happens.
- source/TaskQueue.cpp, source/audio/Audio.cpp: revert to upstream.
Requires COOP/COEP headers for SharedArrayBuffer; the deploy already sets them.
NOT MERGED: Safari reloads the page ("this page was reloaded because it used
significant memory") on both emscripten 5.0.1 and 6.0.6, at 2GB, 1GB and even
512MB/1GB caps. pthreads force the heap to be a SharedArrayBuffer, which cannot
be relocated on growth, so a maximum must be declared up front and Safari
appears to commit it rather than lazily map it. Measured peak usage is only
~531-637MB, of which ~383MB is the preloaded asset bundle resident in MEMFS for
the whole session -- so shrinking that is the most promising route to making
this shippable. Chrome and Firefox are fine and load noticeably faster.
thomasballinger
force-pushed
the
threads
branch
from
August 8, 2026 23:26
45c1d8c to
3bfe2fc
Compare
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:26 — with
GitHub Actions
Inactive
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:26 — with
GitHub Actions
Inactive
thomasballinger
temporarily deployed
to
aws-deploy
August 8, 2026 23:26 — with
GitHub Actions
Inactive
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.
Rebases the browser port onto current upstream master and restores the threaded
build (#38). Six commits on top of
master, which now tracks upstream44375632f(v0.11.2 + 142 commits).The claim to check: C++ changes for threading are now zero
source/TaskQueue.cppandsource/audio/Audio.cppare byte-identical toupstream. The whole threading change is build configuration:
Makefile:-pthreadinCOMMON_FLAGS,-s PTHREAD_POOL_SIZE=10endless-sky.html: pass--tq-threads NtocallMainThat last one uses a CLI flag upstream already has (
main.cpp->TaskQueue::SetWorkerThreadCount), so no C++ patch is needed to keep theworker count within the preallocated pool. Overflowing the pool makes
Emscripten create threads on demand, which needs the main thread to reach the
event loop -- and it may be blocked in the game loop when that happens.
Previously this cost 55 lines (
TaskQueue.cpp+43,Audio.cpp+12).Remaining C++ diff: 115 lines in 7 files
LoadPanel.cppFS.syncfsafter snapshot/deleteFiles.cpp/, stubZipFilePlayerInfo.cppFS.syncfsafter save/autosavemain.cpp/savesImageBuffer.cppaudio/Music.cppGameWindow.cppRoughly 60 of those 115 lines are hand-rolled IDBFS save syncing, which
Emscripten's
IDBFS { autoPersist: true }(3.1.61) could replace outright.Not attempted here.
Also included
Audio::LoadSounds(); a previous rebase guarded the whole call rather thanjust the thread spawn, so no sound was ever queued.
endless-sky.jswas hashed before its.wasmreference was rewritten into it, so two builds differing only in C++ shared a
filename of identical length, and
aws s3 sync --size-onlyskipped theupload. This silently shipped stale wasm.
Makefileis now a prerequisite of the link, so changingLINK_FLAGSactually relinks.
Checkworkflow passes.Not ready to merge
Safari reloads the threaded build ("this page was reloaded because it used
significant memory"), at both 2GB and 1GB caps. Chrome is fine and loads
noticeably faster.
pthreads force the heap to be a
SharedArrayBuffer, which cannot be relocatedon growth, so a maximum must be declared up front and engines reserve it.
Safari appears to commit rather than lazily map. The single-threaded build
declares no maximum in JS and grows lazily -- same
INITIAL_MEMORY, verydifferent real footprint.
Measured peak (headless,
--parse-assets): 637 MB, of which ~383 MB isthe preloaded asset bundle resident in MEMFS for the whole session. Shrinking
that looks more promising than tuning flags, and would help the
single-threaded build too.