fix: allow wasm memory growth for sources over ~4MB#217
Merged
Conversation
The emsdk toolchain update in #203 dropped the growable memory the old fastcomp build emitted: the wasm memory was declared with maximum == initial (258 pages / ~16MiB), so the unconditional memory.grow() in parse() throws "Maximum memory size exceeded" for any source over ~4M chars (stored as 4 bytes per char). Add -s ALLOW_MEMORY_GROWTH=1 to restore growable memory, and a 5MB large source regression test. Fixes #214
guybedford
force-pushed
the
fix/wasm-memory-growth
branch
from
July 2, 2026 00:50
d1c8c21 to
cec78bb
Compare
guybedford
enabled auto-merge (squash)
July 2, 2026 00:51
guybedford
added a commit
that referenced
this pull request
Jul 2, 2026
…e readme (#219) The minimal wasm build added in #211 predates the #217 memory growth fix and was missing -s ALLOW_MEMORY_GROWTH=1, so parse() on sources over ~4M chars threw "Maximum memory size exceeded" (the Large source test from #217 catches this under test:minimal:wasm). Also documents the es-module-lexer/minimal build in the readme, and corrects the stale comments claiming dynamic-import n / ip() are dropped in the minimal build: _ip is exported and read, only at/ss/f/ms go.
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.
Fixes #214.
Root cause
The emsdk toolchain update in #203 (shipped in 2.2.0) regressed the wasm memory declaration. The old fastcomp build emitted growable memory (min 1 page, no maximum), but the upstream emscripten build defaults to fixed-size memory:
0x00x1With
maximum == initial, the unconditionalmemory.grow()inparse()throwsWebAssembly.Memory.grow(): Maximum memory size exceededfor any source that doesn't fit the initial 16 MiB. Since the source is copied in as UTF-16 (4 * (len + 1)bytes), that's the ~4M char threshold reported in the issue. The asm.js build was unaffected.Fix
Add
-s ALLOW_MEMORY_GROWTH=1to the emcc build, restoring growable memory (max 32768 pages / 2 GiB, emscripten's default ceiling — ~512M chars of source).The issue repro now passes against the rebuilt
dist/lexer.js:Also adds a 5MB large-source regression test, verified to fail against a fresh build off main and pass with this change;
chomp testpasses (149 tests, wasm + asm).