Merged
Conversation
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
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>
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.
pthreads + ASYNCIFY conflict:
emscripten_sleep()doesn't yield properly when pthreads are active. Removing-pthreadmakes 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