Repository navigation
perf: do each block's open-time work once in main's parse (huge parse 325 → 225 ms) - #325
Merged
Merged
Conversation
engineOwnedSemanticKey asks canSkipDialectEnrich and engineSemanticKey in one parse (lists, tables, footnote and link definitions were parsed twice). Main hashes with Node's one-shot crypto.hash instead of a Hash object per block. detectLineEnding and toLf skip text with no carriage return.
# Conflicts: # docs/performance/measurements.md
Merged
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.
What
Main's
parseDocumentrepeated per-block work on open. Profiled on the 8 MB document (~320 ms in Node):engineOwnedSemanticKey(kind, md)returnscanSkipDialectEnrich ? engineSemanticKey : nullin one parse. Lists, tables, footnote and link definitions used to be parsed twice (tables: 24 + 22 ms).enrichSpanNoneuses it.engineSemanticKeyshares the list and table key builders, so the two can't drift.nativeSha256, which callscrypto.hash('sha256', v, 'hex')(Node ≥ 21.7; Electron ships 24) and falls back tocreateHash. Same digest, without a Hash object per block: 44 → 19 ms for 43,970 blocks. Saves get the benefit too.detectLineEndinganswerslfimmediately when the text has no\r, otherwise steps through withindexOf(was a 24 ms per-character loop).toLfreturns LF text unchanged.Correctness
tests/unit/main-parse-once.test.ts:nativeSha256equalscreateHashfor strings (incl. lone surrogates) and bytesdetectLineEndingequals the old scan on edge cases and on LF/CRLF goldenstoLfoutput unchangedNumbers (huge, 8 MB, 43,970 blocks)
parseDocument, Node, median of 11, ×3 interleavedparseDocument, profiled ×3BENCH_RUNS=5, ×2Packaged runs: Linux x64, Xvfb, interleaved with the build before. Typecheck and full unit suite green.
Left in main's parse: engine split ~60 ms,
tryInlineNodesFromSourcebuilding PM nodes just to test ownership ~40 ms, lazy span objects ~20 ms, GC.