Skip to content

jsg: skip the fast-callback preamble and restore FastOneByteString - #7695

Open
littledivy wants to merge 1 commit into
cloudflare:mainfrom
littledivy:littledivy/2026-10-11-fast-api-no-scope
Open

littledivy wants to merge 1 commit into
cloudflare:mainfrom
littledivy:littledivy/2026-10-11-fast-api-no-scope

Conversation

@littledivy

@littledivy littledivy commented Oct 11, 2026 •

Copy link
Copy Markdown

I was digging into the JSG fast API implementation and found some overhead to remove. Skimming through the git history, it might be enough to make enabling fast calls worth another look.

This patch includes two changes:

  1. Skip the HandleScope. Every fast callback opens a HandleScope, grabs the current context, and does two isolate lookups. That is all only needed to unwrap v8::Local arguments. If a method takes nothing but primitives and strings then there is nothing to unwrap, so none of it is needed.
  2. Bring back FastOneByteString. It was removed in remove v8::FastOneByteString support #4628 because its data pointer dies on the next GC and unwrapping another argument could trigger one first. For these signatures no argument calls into V8 at all, so nothing can GC before we copy the bytes.

Ran //src/workerd/jsg:bench-dispatch with --config=benchmark and 3 reps:

before after
NativeDispatchFast 58.6 us 34.9 us
NativeDispatchFastArg 58.3 us 35.8 us

I also measured Headers locally:

method slow fast
has 52.5 ns 37.2 ns -29.1%
set 101.3 ns 89.0 ns -12.1%
delete 51.4 ns 43.2 ns -16.0%

I will open follow up PRs that apply the same optimizations to the preamble in the 10 other fastCallback definitions.

@littledivy
littledivy requested review from a team as code owners October 11, 2026 09:46
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@littledivy
littledivy force-pushed the littledivy/2026-10-11-fast-api-no-scope branch from ad5b3eb to 82b7ff4 Compare October 11, 2026 09:47
@littledivy

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 11, 2026
@littledivy
littledivy force-pushed the littledivy/2026-10-11-fast-api-no-scope branch from 82b7ff4 to e8fe089 Compare October 11, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant