chore(bench): add parse-phase benchmark - #126
Merged
Merged
Conversation
Split parse cost into four phases on the same input: A parseMd, B bare fromMarkdown, B2 B + recordingExtension, C parseMdWithSourceMap. Report derived A-B, B2-B, C-B2, and C-B. Run each measured sample in its own child process. The parent only aggregates. A single process builds a large multiline AST with heavy GC churn, so an in-process median flips between runs. Add bench:parse and a Node 22 smoke step. The smoke checks finite output, AST parity, and 4x input growth. It does not check absolute wall time.
Rename C-B2 to post-parse source-map setup / indexing. C-B2 also covers RecordingState / WeakMap creation, the recordingExtension(state) call, parse-time snapshots, and the sourceMap object with its closures. The harness does not time indexNode alone. Relax and explain the smoke growth comment. A 4x input can grow more than 5x and stay linear. The 10x budget only catches severe regressions. Delete a temp bundle directory only when this script created it. A caller-supplied BENCH_PARSE_BUNDLE is no longer removed.
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
scripts/bench-parse.mjs.bench:parsescript.Phases
The benchmark measures four phases on the same input:
parseMdfromMarkdown+ parser extensionsrecordingExtensionparseMdWithSourceMapDerived values: A-B (remark wrapper), B2-B (recording), C-B2 (post-parse source-map setup / indexing), C-B (total source-map increment).
indexNodeis likely most of C-B2, but this harness does not time it alone.C-B2 also covers RecordingState / WeakMap creation, the
recordingExtension(state)call, parse-time snapshots, and the sourceMap object with its closures.Each measured sample runs in its own child process.
The parent only aggregates.
A single process builds a large multiline AST with heavy GC churn, so an in-process median flips between runs.
Findings (256 KiB, local)
recording and post-parse setup stay near zero.
recording is about 190 ms.
post-parse setup is about 26 ms.
The benchmark does not identify one slow micromark tokenizer yet.
Smoke design
Note: multiline-hmd grows super-linearly at large sizes.
The min ratio from 64 KiB to 256 KiB is about 15x on a 4x input.
The smoke uses 16 KiB to 64 KiB and a 10x budget instead.
This keeps the check stable and still catches a gross regression.
Validation
pnpm run lintpnpm run buildpnpm run testnode scripts/bench-parse.mjs --smokenode scripts/bench-parse.mjs --shapes single-line,entity-dense,escape-dense,many-paragraphs,large-code-block --sizes 65536 --runs 1Closes #125