ffi: shrink trampoline placement probe window - #64969
Open
trivikr wants to merge 1 commit into
Open
Conversation
AllocateCodeNear() searched 1024 pages in each direction for a free page next to the native target, one MAP_FIXED_NOREPLACE mmap per candidate. Every probe is expected to fail, so an exhausted window cost up to 2048 failing syscalls before taking the plain-mmap fallback that was already there, all to enable a jmp rel32 instead of movabs+jmp. Resolving a fast-eligible signature plateaued at ~790us, against ~28us for one that allocates no trampoline. Reduce the window to 16 pages per direction, bounding the exhausted case to 32 probes while still covering typical per-library symbol counts. Placement stays opportunistic: the caller already emits the absolute form when EmitJmpRel32() reports the target is out of range. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64969 +/- ##
=======================================
Coverage 90.27% 90.27%
=======================================
Files 762 762
Lines 247515 247515
Branches 46683 46681 -2
=======================================
Hits 223447 223447
- Misses 15485 15491 +6
+ Partials 8583 8577 -6 🚀 New features to boost your workflow:
|
ShogunPanda
approved these changes
Aug 3, 2026
Collaborator
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.
Fixes: #64968
AllocateCodeNear()searched1024pages in each direction for a free page next to the native target, oneMAP_FIXED_NOREPLACEmmap per candidate. Every probe is expected to fail, so an exhausted window cost up to 2048 failing syscalls before taking the plain-mmap fallback that was already there, all to enable a jmp rel32 instead of movabs+jmp. Resolving a fast-eligible signature plateaued at~790us, against~28usfor one that allocates no trampoline.Reduce the window to
16pages per direction, bounding the exhausted case to32probes while still covering typical per-library symbol counts. Placement stays opportunistic: the caller already emits the absolute form whenEmitJmpRel32()reports the target is out of range.Add
benchmark/ffi/get-function.js, which measures resolution rather than call throughput, so this path has coverage. Its fast arm reports 1,852 ops/sec at the old window and 37,836 at the new one, with the fast-ineligible control arm flat at ~80,000.Assisted-by: claude:opus-5