Skip to content

fix(wasm): drop pthreads — fixes UI hang#32

Merged
unamedkr merged 1 commit intomainfrom
fix/wasm-drop-pthreads-fix-hang
Apr 10, 2026
Merged

fix(wasm): drop pthreads — fixes UI hang#32
unamedkr merged 1 commit intomainfrom
fix/wasm-drop-pthreads-fix-hang

Conversation

@unamedkr
Copy link
Copy Markdown
Collaborator

pthreads + ASYNCIFY conflict: emscripten_sleep() doesn't yield properly when pthreads are active. Removing -pthread makes ASYNCIFY sleep work correctly — both prefill and generation now yield to the browser, eliminating the hang.

Binary: 384K → 320K. SIMD + O3 + relaxed-simd retained.

🤖 Generated with Claude Code

pthreads + ASYNCIFY conflict: emscripten_sleep() on the main thread
doesn't yield properly when pthreads are active (Atomics.wait-based
scheduling interferes with ASYNCIFY's stack unwinding). Result: UI
hangs during both prefill and generation despite yield calls.

Fix: remove -pthread and PTHREAD_POOL_SIZE. Keep ASYNCIFY + SIMD128
+ relaxed-simd + O3 + LTO. The emscripten_sleep(0) calls in both
prefill (every 2 tokens) and generation (every 4 tokens) now work
correctly, keeping the browser responsive.

quant.h's matmul still uses pthread_create internally, but without
-pthread they become no-ops in Emscripten — single-threaded matmul
with SIMD vectorization.

Binary: 384K → 320K (-17%, no pthread runtime).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@unamedkr unamedkr merged commit 3df9a49 into main Apr 10, 2026
@unamedkr unamedkr deleted the fix/wasm-drop-pthreads-fix-hang branch April 10, 2026 11:12
unamedkr added a commit that referenced this pull request Apr 10, 2026
The emscripten_sleep(0) added to quant.h's prefill loop (PR #30)
broke ASYNCIFY for the entire quant_generate call. The call stack
during tq_forward() is too deep (matmul → SIMD kernels) for
ASYNCIFY to unwind/rewind — it silently fails and the generation
callback's sleep stops working too.

Fix: remove prefill sleep entirely. The prefill blocks the browser
for a few seconds (unavoidable without a step-by-step API), but
"Thinking..." is shown before via requestAnimationFrame. Token
streaming during generation works again.

Also: pthreads removed (PR #32) to avoid pthreads+ASYNCIFY
conflict, build.sh now uses single-thread SIMD + ASYNCIFY only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
unamedkr added a commit that referenced this pull request Apr 10, 2026
)

The emscripten_sleep(0) added to quant.h's prefill loop (PR #30)
broke ASYNCIFY for the entire quant_generate call. The call stack
during tq_forward() is too deep (matmul → SIMD kernels) for
ASYNCIFY to unwind/rewind — it silently fails and the generation
callback's sleep stops working too.

Fix: remove prefill sleep entirely. The prefill blocks the browser
for a few seconds (unavoidable without a step-by-step API), but
"Thinking..." is shown before via requestAnimationFrame. Token
streaming during generation works again.

Also: pthreads removed (PR #32) to avoid pthreads+ASYNCIFY
conflict, build.sh now uses single-thread SIMD + ASYNCIFY only.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant