perf(parser): specialized fast path for default-option parsing#15
Merged
Conversation
Routes default-option parse() calls to a module-level loop with option checks constant-folded and no per-call closures. Adds deferred ignorable-whitespace handling, offset-based close-tag verification, fused text scanning, and an inline name="value" attribute fast path. 1.2-1.6x faster across fixtures; verified against the previous parser with a 30k-case differential fuzz across option combinations.
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.
Applies the experiment-loop methodology (4 parallel agents on isolated copies, winners combined and measured stepwise) to the tree parser, which had fallen behind the SAX engine after the recent perf rounds.
What went in
parse()dispatcher: default-option calls route to a module-levelparseRootFastwith every option check constant-folded,posas a true local (helpers inlined), and zero per-call closure allocation. Optioned calls take the untouched general path.substring().trimEnd()per close tag.name="value"fast path, entity-decode gated on&presence.Measured and rejected
Parallel-array stacks, bounded JS pre-scan before SIMD
indexOf, switch reordering.Results
Now 1.7-2.2x faster than tXml across fixtures. Confirmed in the browser demo (~318k → ~505k ops/s).
Verification
scripts/generate-char-codes.ts(idempotent)Trade-offs
parseRootFastduplicates ~430 lines ofparseChildrenlogic (semantic changes must be made in both; the parity gate + suite guard this), and module-level scratch buffers assumeparseis never re-entered mid-call (holds today — no user callbacks run during tree building). BENCHMARKS.md DOM table and README claims regenerated.