From a979326cadfd873d879a331a972f858fa76a4222 Mon Sep 17 00:00:00 2001 From: Nigro Simone Date: Sun, 27 Sep 2026 10:33:58 +0200 Subject: [PATCH] src: do not shrink async resources on every pop AsyncHooks::pop_async_context() calls shrink_to_fit() on native_execution_async_resources_ after every pop. With the MSVC and libc++ standard libraries, shrink_to_fit() on an empty std::deque frees its storage, so every top-level callback scope allocates it again on push and frees it on pop. libstdc++ does nothing here. A program with the same pattern, a std::deque of the same variant going from 0 to 1 to 0 elements, takes 136-147 ns per callback on Windows with MSVC, and 6 ns without shrink_to_fit(). The async_ids_stack_ next to it never shrinks either. Refs: https://github.com/nodejs/performance/issues/24 Signed-off-by: Nigro Simone --- src/env.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/env.cc b/src/env.cc index 33e2121d45f..68efb5268a8 100644 --- a/src/env.cc +++ b/src/env.cc @@ -205,7 +205,6 @@ bool AsyncHooks::pop_async_context(double async_id) { } else { native_execution_async_resources_.resize(offset); } - native_execution_async_resources_.shrink_to_fit(); } if (js_execution_async_resources()->Length() > offset) [[unlikely]] {