Repository navigation
perf(lexer): skip identifier and number runs - #227
Merged
guybedford merged 2 commits intoJul 13, 2026
Merged
Conversation
On the 3,057 KiB sample corpus, Wasm drops from 15,356.31 to 13,010.46 us per sweep on Node 18.20.8 (-15.28%) and from 11,724.34 to 9,856.69 us on Node 24.18.0 (-15.93%). The asm.js build drops from 15,934.34 to 12,945.57 us on Node 24.18.0 (-18.76%). The fast path adds 379 raw / 105 gzip bytes to the full Wasm binary. Measurements used 1,500 warmup sweeps followed by 9 interleaved trials of 50 sweeps, dropping the best and worst trials.
guybedford
approved these changes
Jul 13, 2026
guybedford
enabled auto-merge (squash)
July 13, 2026 00:58
guybedford
added a commit
that referenced
this pull request
Aug 9, 2026
…205) * perf(lexer): skip identifier and number runs (#227) * perf(lexer): skip identifier and number runs On the 3,057 KiB sample corpus, Wasm drops from 15,356.31 to 13,010.46 us per sweep on Node 18.20.8 (-15.28%) and from 11,724.34 to 9,856.69 us on Node 24.18.0 (-15.93%). The asm.js build drops from 15,934.34 to 12,945.57 us on Node 24.18.0 (-18.76%). The fast path adds 379 raw / 105 gzip bytes to the full Wasm binary. Measurements used 1,500 warmup sweeps followed by 9 interleaved trials of 50 sweeps, dropping the best and worst trials. * chore: remove the unmaintained pure-JS lexer port lexer.js reimplemented the WebAssembly lexer in hand-written JS, kept in sync by hand, but was unreachable through the package `exports` (only `.` and `./js` are exposed - the wasm and asm.js builds) and `chomp test` never ran it, so it could drift silently. The asm.js build already covers the no-WebAssembly case, and the removed `if (!js)` test guards now run unconditionally, matching their existing behavior under the wasm and asm suites. * feat: report glob n for interpolated template dynamic imports A dynamic import whose entire argument is a template literal with substitutions returned n: undefined, so a consumer resolving the specifier (a bundler or glob importer) had nothing to work with. It now reports the static skeleton as a glob with each ${...} collapsed to a single "*": import(`./locales/${x}.js`) yields "./locales/*.js". Only a lone template literal qualifies. A template concatenated with anything else (import(`a` + b)) has no static skeleton and still returns undefined. Fixes: #137 * fix: drop interpolated template glob to undefined on ambiguous slash The glob walker that builds a dynamic-import template skeleton skips over strings, nested templates, and comments inside each ${...} substitution, but it cannot tell a regex literal from division without the main parser's token context. A regex carrying a "}" closed the substitution early and emitted a wrong specifier instead of bailing: import(`a${ /x}y/g }b`) reported "a*y/g }b" rather than undefined. skipInterpolation now flags a bare "/" (one that does not open a // or /* comment) and the three decoders drop n to undefined rather than guess. This over-bails the rare division case (import(`a${ b/c }d`)), which is acceptable: a missing glob is recoverable, a wrong one is not. Fixes: #137 * refactor: disambiguate template glob substitutions in the parser The interpolated-template glob walked each ${...} substitution with a hand-rolled scanner in all three decoders. None of them could tell a regex literal from division without token context, so a regex carrying a "}" closed the substitution early: import(`a${ /x}y/g }b`) reported "a*y/g }b". The prior fix bailed to undefined on any bare "/", which also dropped legitimate division (import(`a${ b/c }d`)). The parser already resolves regex vs division for the whole source and descends into ${ ... } for nested-import detection, so it now records each top-level substitution's end on the dynamic import (struct TemplateSpan). The decoders splice a "*" per span and jump the body, dropping their skipInterpolation / skipQuoted / skipComment scanners and the interpolationError bail. Both ambiguous cases now resolve correctly: "a*b" and "a*d". Fixes: #137 * fix: gate template glob to the full build and fix its cross-build defects ## Summary Interpolated template glob tracking leaked into minimal builds and diverged between decoders. Missing parser spans could evaluate a substitution, reload an exhausted span list into a loop, or lose the outer glob around a nested import. ## Why Keep span tracking behind LEXER_MIN, use parser-recorded spans as the substitution boundary, and copy static source without eval. The full Wasm and asm.js builds now agree while minimal output stays unchanged. Static parts remain raw source, so escapes are not cooked and a literal * stays literal. ## Test plan - chomp test Fixes: #137 * fix: escape literal stars in template glob output --------- Co-authored-by: Guy Bedford <guybedford@gmail.com>
guybedford
added a commit
that referenced
this pull request
Aug 17, 2026
…205) * perf(lexer): skip identifier and number runs (#227) * perf(lexer): skip identifier and number runs On the 3,057 KiB sample corpus, Wasm drops from 15,356.31 to 13,010.46 us per sweep on Node 18.20.8 (-15.28%) and from 11,724.34 to 9,856.69 us on Node 24.18.0 (-15.93%). The asm.js build drops from 15,934.34 to 12,945.57 us on Node 24.18.0 (-18.76%). The fast path adds 379 raw / 105 gzip bytes to the full Wasm binary. Measurements used 1,500 warmup sweeps followed by 9 interleaved trials of 50 sweeps, dropping the best and worst trials. * chore: remove the unmaintained pure-JS lexer port lexer.js reimplemented the WebAssembly lexer in hand-written JS, kept in sync by hand, but was unreachable through the package `exports` (only `.` and `./js` are exposed - the wasm and asm.js builds) and `chomp test` never ran it, so it could drift silently. The asm.js build already covers the no-WebAssembly case, and the removed `if (!js)` test guards now run unconditionally, matching their existing behavior under the wasm and asm suites. * feat: report glob n for interpolated template dynamic imports A dynamic import whose entire argument is a template literal with substitutions returned n: undefined, so a consumer resolving the specifier (a bundler or glob importer) had nothing to work with. It now reports the static skeleton as a glob with each ${...} collapsed to a single "*": import(`./locales/${x}.js`) yields "./locales/*.js". Only a lone template literal qualifies. A template concatenated with anything else (import(`a` + b)) has no static skeleton and still returns undefined. Fixes: #137 * fix: drop interpolated template glob to undefined on ambiguous slash The glob walker that builds a dynamic-import template skeleton skips over strings, nested templates, and comments inside each ${...} substitution, but it cannot tell a regex literal from division without the main parser's token context. A regex carrying a "}" closed the substitution early and emitted a wrong specifier instead of bailing: import(`a${ /x}y/g }b`) reported "a*y/g }b" rather than undefined. skipInterpolation now flags a bare "/" (one that does not open a // or /* comment) and the three decoders drop n to undefined rather than guess. This over-bails the rare division case (import(`a${ b/c }d`)), which is acceptable: a missing glob is recoverable, a wrong one is not. Fixes: #137 * refactor: disambiguate template glob substitutions in the parser The interpolated-template glob walked each ${...} substitution with a hand-rolled scanner in all three decoders. None of them could tell a regex literal from division without token context, so a regex carrying a "}" closed the substitution early: import(`a${ /x}y/g }b`) reported "a*y/g }b". The prior fix bailed to undefined on any bare "/", which also dropped legitimate division (import(`a${ b/c }d`)). The parser already resolves regex vs division for the whole source and descends into ${ ... } for nested-import detection, so it now records each top-level substitution's end on the dynamic import (struct TemplateSpan). The decoders splice a "*" per span and jump the body, dropping their skipInterpolation / skipQuoted / skipComment scanners and the interpolationError bail. Both ambiguous cases now resolve correctly: "a*b" and "a*d". Fixes: #137 * fix: gate template glob to the full build and fix its cross-build defects ## Summary Interpolated template glob tracking leaked into minimal builds and diverged between decoders. Missing parser spans could evaluate a substitution, reload an exhausted span list into a loop, or lose the outer glob around a nested import. ## Why Keep span tracking behind LEXER_MIN, use parser-recorded spans as the substitution boundary, and copy static source without eval. The full Wasm and asm.js builds now agree while minimal output stays unchanged. Static parts remain raw source, so escapes are not cooked and a literal * stays literal. ## Test plan - chomp test Fixes: #137 * fix: escape literal stars in template glob output --------- Co-authored-by: Guy Bedford <guybedford@gmail.com>
mergify Bot
added a commit
to ArcadeData/arcadedb
that referenced
this pull request
Aug 23, 2026
…2.3.2 in /studio [skip ci] Bumps [es-module-lexer](https://github.com/guybedford/es-module-lexer) from 2.3.1 to 2.3.2. Release notes *Sourced from [es-module-lexer's releases](https://github.com/guybedford/es-module-lexer/releases).* > 2.3.2 > ----- > > What's Changed > -------------- > > * perf(lexer): skip identifier and number runs by [`@BridgeAR`](https://github.com/BridgeAR) in [guybedford/es-module-lexer#227](https://redirect.github.com/guybedford/es-module-lexer/pull/227) > * fix: annotate asm.js integer return type by [`@Justineo`](https://github.com/Justineo) in [guybedford/es-module-lexer#230](https://redirect.github.com/guybedford/es-module-lexer/pull/230) > * Add side effects to package.json by [`@denisx`](https://github.com/denisx) in [guybedford/es-module-lexer#183](https://redirect.github.com/guybedford/es-module-lexer/pull/183) > * fix: forward the sourcename through the pre-init parse path by [`@hdimer`](https://github.com/hdimer) in [guybedford/es-module-lexer#236](https://redirect.github.com/guybedford/es-module-lexer/pull/236) > > New Contributors > ---------------- > > * [`@Justineo`](https://github.com/Justineo) made their first contribution in [guybedford/es-module-lexer#230](https://redirect.github.com/guybedford/es-module-lexer/pull/230) > * [`@denisx`](https://github.com/denisx) made their first contribution in [guybedford/es-module-lexer#183](https://redirect.github.com/guybedford/es-module-lexer/pull/183) > * [`@hdimer`](https://github.com/hdimer) made their first contribution in [guybedford/es-module-lexer#236](https://redirect.github.com/guybedford/es-module-lexer/pull/236) > > **Full Changelog**: <guybedford/es-module-lexer@2.3.1...2.3.2> Commits * [`08ee1be`](guybedford/es-module-lexer@08ee1be) fix: forward the sourcename through the pre-init parse path ([#236](https://redirect.github.com/guybedford/es-module-lexer/issues/236)) * [`5a824a1`](guybedford/es-module-lexer@5a824a1) Update package.json ([#183](https://redirect.github.com/guybedford/es-module-lexer/issues/183)) * [`8274d03`](guybedford/es-module-lexer@8274d03) fix: annotate asm.js integer return type ([#230](https://redirect.github.com/guybedford/es-module-lexer/issues/230)) * [`2abc49e`](guybedford/es-module-lexer@2abc49e) perf(lexer): skip identifier and number runs ([#227](https://redirect.github.com/guybedford/es-module-lexer/issues/227)) * See full diff in [compare view](guybedford/es-module-lexer@2.3.1...2.3.2) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Merged
guybedford
added a commit
that referenced
this pull request
Sep 7, 2026
## Breaking * **Full build records are tagged unions** discriminated by `type` (`static` | `reexport-star` | `dynamic` | `import-meta`; `direct` | `reexport` | `reexport-all`) with descriptive fields (`specifier`, `importStart`/`importEnd`, `attributes`, `phase`, `name`, `localName`, `from`, `importIndex`, `exportStart`) replacing the terse v2 names and numeric type tags. (#233) * **`es-module-lexer/minimal`** is a new entry point holding the v2-shaped API: `parse` returns `[imports, exports]` only; `at` is dropped (read attributes via `source.slice(a, se - 1)`); `export { a as b } from 'c'` reports the imported name in `ln`/`ls`/`le`. (#211, #240) * **`ImportType`** is a type-only union of named numeric literal aliases (`StaticImportType = 1`, `DynamicImportType = 2`, …); no runtime enum is exported. `initSync` is no longer exported — `parse` initializes on first use. (#240) * **`es-module-lexer/js`** is the asm.js build; the unmaintained pure-JS port is removed. (#204) * Invalid escape sequences in static specifiers throw a parse error instead of yielding `undefined`. (#238) * Node.js 18+ is required. (#232) ## Features * **TypeScript**: type-only imports, exports, aliases, interfaces and ambient declarations are lexed as accepted by Node.js type stripping; type-only edges carry `typeOnly`, dynamic imports carry a best-effort `probablyTypeOnly`, and erased declaration bodies never leak nested `import()` types. Full builds only. (#220, #241) * **Export origin analysis**: reexports resolve to their originating import (`importName`, `from`, `importIndex`) regardless of statement order; `export * from` appears in `exports` as `reexport-all` and its import as `reexport-star`. (#229) * **Template globs**: a dynamic import whose argument is a single template literal reports a glob specifier with each `${…}` collapsed to `*` (`./locales/*.js`), disambiguated by the parser so regex/division inside substitutions is handled. (#205) * Dynamic import `attributes` is typed `null`; the options argument is located by `attributesStart`. (#240) * `parse` initializes the Wasm synchronously on first call; `await init` is only required on browser main threads, and all four entry points export the same `parse` / `init` API. (#237, #240) ## Performance * SIMD scanning for long line comments and templates in the full Wasm build (the minimal build stays Wasm MVP). (#231, #235) * Identifier and number runs are skipped in bulk: ~15% faster sweeps across Wasm and asm.js. (#227) * Module strings decode without `eval`: one-import parse 354 → 238 ns, and the Wasm builds now work under `--disallow-code-generation-from-strings`. (#239) * Short sources (< 64 chars) copy via the typed-array loop rather than `Buffer`. (#242) * Strict specifier decoding avoids V8's sloppy/strict cache mismatch. (#220) ## Fixes * Bounds checks on the open-token and dynamic-import stacks; nesting past 1024 brackets or 512 dynamic imports is a parse error rather than memory corruption. (#243) * Unannotated `declare let`/`var` and shorthand `declare module 'm'` no longer erase the following statement; `export default interface Foo {}` reports `Foo` as its local name. (#241) * Typed export binding lists collect every declarator; `export { type as }` / `type as as` follow TypeScript's specifier table; U+00A0 is whitespace around import/export names. (#220) * Minimal build enforces Wasm MVP (no post-MVP features) and is tested in Firefox 67. (#234) ## Docs & tooling * README restructured: package exports table with Brotli footprint and cold/warm parse speed per MB, environment/CSP/usage up front, minimal-build "Upgrading from v2" section, WASI build steps replaced by the emsdk checkouts the build installs itself. (#240) * `chomp bench` runs all four builds in one process and prints the README table; generated `types/` are tracked in the repo. (#240) * TypeScript differential fuzzer against `stripTypeScriptTypes` in CI; no-eval lanes for minimal and CommonJS. (#220, #239)
guybedford
added a commit
that referenced
this pull request
Sep 7, 2026
…205) * perf(lexer): skip identifier and number runs (#227) * perf(lexer): skip identifier and number runs On the 3,057 KiB sample corpus, Wasm drops from 15,356.31 to 13,010.46 us per sweep on Node 18.20.8 (-15.28%) and from 11,724.34 to 9,856.69 us on Node 24.18.0 (-15.93%). The asm.js build drops from 15,934.34 to 12,945.57 us on Node 24.18.0 (-18.76%). The fast path adds 379 raw / 105 gzip bytes to the full Wasm binary. Measurements used 1,500 warmup sweeps followed by 9 interleaved trials of 50 sweeps, dropping the best and worst trials. * chore: remove the unmaintained pure-JS lexer port lexer.js reimplemented the WebAssembly lexer in hand-written JS, kept in sync by hand, but was unreachable through the package `exports` (only `.` and `./js` are exposed - the wasm and asm.js builds) and `chomp test` never ran it, so it could drift silently. The asm.js build already covers the no-WebAssembly case, and the removed `if (!js)` test guards now run unconditionally, matching their existing behavior under the wasm and asm suites. * feat: report glob n for interpolated template dynamic imports A dynamic import whose entire argument is a template literal with substitutions returned n: undefined, so a consumer resolving the specifier (a bundler or glob importer) had nothing to work with. It now reports the static skeleton as a glob with each ${...} collapsed to a single "*": import(`./locales/${x}.js`) yields "./locales/*.js". Only a lone template literal qualifies. A template concatenated with anything else (import(`a` + b)) has no static skeleton and still returns undefined. Fixes: #137 * fix: drop interpolated template glob to undefined on ambiguous slash The glob walker that builds a dynamic-import template skeleton skips over strings, nested templates, and comments inside each ${...} substitution, but it cannot tell a regex literal from division without the main parser's token context. A regex carrying a "}" closed the substitution early and emitted a wrong specifier instead of bailing: import(`a${ /x}y/g }b`) reported "a*y/g }b" rather than undefined. skipInterpolation now flags a bare "/" (one that does not open a // or /* comment) and the three decoders drop n to undefined rather than guess. This over-bails the rare division case (import(`a${ b/c }d`)), which is acceptable: a missing glob is recoverable, a wrong one is not. Fixes: #137 * refactor: disambiguate template glob substitutions in the parser The interpolated-template glob walked each ${...} substitution with a hand-rolled scanner in all three decoders. None of them could tell a regex literal from division without token context, so a regex carrying a "}" closed the substitution early: import(`a${ /x}y/g }b`) reported "a*y/g }b". The prior fix bailed to undefined on any bare "/", which also dropped legitimate division (import(`a${ b/c }d`)). The parser already resolves regex vs division for the whole source and descends into ${ ... } for nested-import detection, so it now records each top-level substitution's end on the dynamic import (struct TemplateSpan). The decoders splice a "*" per span and jump the body, dropping their skipInterpolation / skipQuoted / skipComment scanners and the interpolationError bail. Both ambiguous cases now resolve correctly: "a*b" and "a*d". Fixes: #137 * fix: gate template glob to the full build and fix its cross-build defects ## Summary Interpolated template glob tracking leaked into minimal builds and diverged between decoders. Missing parser spans could evaluate a substitution, reload an exhausted span list into a loop, or lose the outer glob around a nested import. ## Why Keep span tracking behind LEXER_MIN, use parser-recorded spans as the substitution boundary, and copy static source without eval. The full Wasm and asm.js builds now agree while minimal output stays unchanged. Static parts remain raw source, so escapes are not cooked and a literal * stays literal. ## Test plan - chomp test Fixes: #137 * fix: escape literal stars in template glob output --------- Co-authored-by: Guy Bedford <guybedford@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.
Summary
Skip the remainder of identifier and number runs after their first token dispatch, avoiding repeated switch dispatch and
lastTokenPosstores.On the 3,057 KiB sample corpus, Wasm improves from 15,356.31 to 13,010.46 us per sweep on Node 18.20.8 (-15.28%) and from 11,724.34 to 9,856.69 us on Node 24.18.0 (-15.93%). The asm.js build improves from 15,934.34 to 12,945.57 us on Node 24.18.0 (-18.76%). The full Wasm binary grows by 379 raw / 105 gzip bytes.
Test plan