Skip to content

async_hooks: callback trampoline for MakeCallback

This is the start of an effort to eliminate the additional two native-to-JavaScript barrier crosses for the before and after events when async_hooks is active. It also moves the domain callback to be triggered within the trampoline rather than on the native side, when there are before/after events to trigger.

I plan to work on making the domain callback trigger fully JavaScript-side tomorrow which should eliminate the need to even have native-side code for domains. Currently the only native code we have for domains is storing the callback in the environment so it can be triggered from this single location in callback.cc. With that no longer being triggered on the native side there's actually no reason to even store it on the native side so that could be easily eliminated to allow domains to live entirely on the JS side.

I'm also hoping to move the execution async resource stack to be managed purely on the JS side too, through this trampoline. This should eliminate the need for the extra state synchronization code needed in #33575 for the performance gains it aims to make.

Side note: There's no try/catch in the trampoline because it currently relies on InternalCallbackScope to catch errors and handle them appropriately. It's also relying on InternalCallbackScope for other things like timer and microtask management, so some deeper modifications will need to be made if we want to move any of that to the JS side too. Personally, I think it's worth considering, and I plan to continue investigating that idea.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading