src,ffi: create fast-call metadata Symbols lazily - #66015
Merged
nodejs-github-bot merged 1 commit intoSep 15, 2026
Merged
Conversation
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.21% +0.07%
==========================================
Files 751 785 +34
Lines 253639 269701 +16062
Branches 47790 51585 +3795
==========================================
+ Hits 228618 243301 +14683
- Misses 16264 16878 +614
- Partials 8757 9522 +765
🚀 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? |
Member
Author
Yes. However we can't assume when the V8 fix is going to land, and this seems better than reverting the ffi change. |
Collaborator
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
mcollina
force-pushed
the
fix-ffi-fast-api-snapshot-symbols
branch
from
September 14, 2026 19:36
9661374 to
ac480bc
Compare
meixg
approved these changes
Sep 15, 2026
jasnell
approved these changes
Sep 15, 2026
Collaborator
Collaborator
|
Landed in cfdb7e6 |
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.