perf: reuse V8 template for wall profile context objects - #408
Merged
Conversation
Overall package sizeSelf size: 2.62 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.3.1 | 504.33 kB | 504.33 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
🔗 Commit SHA: 176e4e5 | Docs | View more details | Give us feedback! |
IlyasShabi
force-pushed
the
ishabi/dictionary-template-optimization
branch
from
September 10, 2026 09:10
425ea51 to
176e4e5
Compare
IlyasShabi
marked this pull request as ready for review
September 10, 2026 12:49
IlyasShabi
requested review from
nsavoire,
r1viollet and
szegedi
as code owners
September 10, 2026 12:49
szegedi
approved these changes
Sep 11, 2026
szegedi
left a comment
There was a problem hiding this comment.
This looks great!
I guess the maybe obvious next place to subject to this treatment is the tree builder as the nodes are all also identical dictionaries
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
V8’s
DictionaryTemplateoptimizes repeated construction of JS objects with a fixed set of properties. It creates the template once and lets V8 reuse the same object layout for subsequent objects.During wall-profile collection, we materialize one JS context object for every matched sample. Previously, each object was created empty and populated using up to 4 individual property writes. This adds overhead on both the C++ and V8 sides through repeated property operations and object-shape transitions.
This PR caches a
DictionaryTemplateper V8 isolate and uses it to construct these context objects directly with the expected layout.Benchmark
TimeProfiler.stop()phase withprocess.hrtime.bigint().Time per object on main: 379 ns
Time per object on this PR: 185 ns
This reduces construction cost by more than 50%. The generated objects also go from three V8 object shapes to one consistent shape.
DictionaryTemplateis available starting with Node.js 22There are other fixed-shape objects in the time and heap profilers that may benefit from the same optimization. I can address those in follow-up PRs if this approach looks good.