From a3a1b3c024caff6b3d738fa04f47888ed863b181 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 d8851d011725..2e6e480f5fe1 100644 --- a/src/env.cc +++ b/src/env.cc @@ -196,7 +196,6 @@ bool AsyncHooks::pop_async_context(double async_id) { } #endif native_execution_async_resources_.resize(offset); - native_execution_async_resources_.shrink_to_fit(); } if (js_execution_async_resources()->Length() > offset) [[unlikely]] {