src,ffi: create fast-call metadata Symbols lazily - #66015
Open
mcollina wants to merge 1 commit into
Open
Conversation
The FFI fast-call wrappers key per-function metadata on raw FFI functions
using two per-isolate Symbols (kFastArguments / kFastBufferInvoke) that were
declared in src/env_properties.h. Everything in env_properties.h is allocated
while the startup snapshot is built, so each Symbol advances the isolate's
identity-hash RNG before Object.prototype / Function.prototype receive their
snapshot identity hashes. In the snapshot produced for Node 26.4.0+ this
shifted those hashes so a function map (a function whose `length` was
redefined) and a plain-object map (an object literal with an accessor) collide
in V8's 64-slot NormalizedMapCache. Every store into such objects then misses
the inline cache, and the repro reported in the linked issue is roughly 7x
slower.
Create the two Symbols lazily in the FFI binding's Initialize, on the first
run of internalBinding('ffi') at runtime, instead of declaring them in
env_properties.h. They are therefore not allocated during snapshot
serialization and no longer bias the snapshot's prototype identity hashes.
Their export, property layout, and the fast-call feature behavior are
unchanged.
Refs: nodejs#66011
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
Assisted-by: Pi
Collaborator
|
Review requested:
|
ShogunPanda
approved these changes
Sep 13, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66015 +/- ##
==========================================
- Coverage 90.13% 90.00% -0.13%
==========================================
Files 751 785 +34
Lines 253639 269356 +15717
Branches 47790 51309 +3519
==========================================
+ Hits 228618 242446 +13828
- Misses 16264 17403 +1139
- Partials 8757 9507 +750
🚀 New features to boost your workflow:
|
Member
|
Is this just kicking the can down the road? Is this behaviour going to be reintroduced some other time someone decides to define a new environment symbol? |
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.
The FFI fast-call wrappers key per-function metadata on raw FFI functions using two per-isolate Symbols (kFastArguments / kFastBufferInvoke) that were declared in src/env_properties.h. Everything in env_properties.h is allocated while the startup snapshot is built, so each Symbol advances the isolate's identity-hash RNG before Object.prototype / Function.prototype receive their snapshot identity hashes. In the snapshot produced for Node 26.4.0+ this shifted those hashes so a function map (a function whose
lengthwas redefined) and a plain-object map (an object literal with an accessor) collide in V8's 64-slot NormalizedMapCache. Every store into such objects then misses the inline cache, and the repro reported in the linked issue is roughly 7x slower.Create the two Symbols lazily in the FFI binding's Initialize, on the first run of internalBinding('ffi') at runtime, instead of declaring them in env_properties.h. They are therefore not allocated during snapshot serialization and no longer bias the snapshot's prototype identity hashes. Their export, property layout, and the fast-call feature behavior are unchanged.
Fixes #66011
Ai generated, humanly reviewed.