perf(sax): intern attribute names in the engine hot path#16
Merged
Conversation
Repeated attribute names previously materialized a fresh substring per occurrence, and every fresh string handed to the keyed attribute store must be re-internalized by V8 before use as a property key. A small direct-mapped cache (cheap length/first/last fingerprint plus verify loop) returns the same instance for repeated names, so repeat occurrences allocate nothing and the store receives an internalized key. Scoped to attribute names only: benchmarks showed interning tag names is a large net loss on element-dense documents (RSS -22%, POM -24%), while attribute-name interning gains 5-14% on attribute-heavy documents and is neutral elsewhere.
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
Interns attribute names in the SAX engine hot path via a small direct-mapped cache (512 slots, cheap length/first/last-char fingerprint, verify loop for collisions).
Why
Attribute names repeat constantly, and every fresh attribute-name substring handed to the keyed attribute store must be re-internalized by V8 before it can be used as a property key. Returning the same string instance for repeated names means repeat occurrences allocate nothing and the store receives an already-internalized key.
Measured results (Node 22, isolated processes, medians)
Scope is deliberate
Interning is applied to attribute names only. Two rejected variants, kept out with a code comment so they don't get re-attempted:
Also experimented with (and rejected) a manual short-scan fast path replacing
indexOffor attribute values: it only wins on sub-8-char values (the synthetic benchmark shape) and loses ~5-7% on EPG's ~20-char timestamp values — V8's vectorizedindexOfis too good at realistic value lengths.All 838 tests pass.