From 16544c403e086961095835df9f30d94220f6dc13 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 22 Dec 2021 09:25:33 +0100 Subject: [PATCH 1/2] src: skip costly pushing/popping if we pass zeroes as async context --- src/api/callback.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/callback.cc b/src/api/callback.cc index fb0e5586eb400a..fad78956f27d43 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -56,6 +56,12 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, CHECK_NOT_NULL(env); env->PushAsyncCallbackScope(); + // Skip costly pushing/popping if we pass zeroes as async context + if (async_context_.async_id == 0) { + pushed_ids_ = false; + return; + } + if (!env->can_call_into_js()) { failed_ = true; return; From 89afce70bd7d1040d1911665d21c3fe66b611ca4 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 22 Dec 2021 10:09:48 +0100 Subject: [PATCH 2/2] fixup --- src/api/callback.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index fad78956f27d43..d6454c6f5d5bad 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -80,10 +80,10 @@ InternalCallbackScope::InternalCallbackScope(Environment* env, pushed_ids_ = true; - if (asyncContext.async_id != 0 && !skip_hooks_) { + if (!skip_hooks_) { // No need to check a return value because the application will exit if // an exception occurs. - AsyncWrap::EmitBefore(env, asyncContext.async_id); + AsyncWrap::EmitBefore(env, async_context_.async_id); } }