Repository navigation
src: do not shrink async resources on every pop - #66344
nigrosimone wants to merge 1 commit into
Conversation
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66344 +/- ##
==========================================
- Coverage 92.86% 90.50% -2.36%
==========================================
Files 428 797 +369
Lines 195100 278361 +83261
Branches 30147 53500 +23353
==========================================
+ Hits 181175 251936 +70761
- Misses 13597 16809 +3212
- Partials 328 9616 +9288
🚀 New features to boost your workflow:
|
|
@anonrig CI is green and this has your approval for more than 7 days, could you add commit-queue? |
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: nodejs/performance#24 Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
a3a1b3c to
a979326
Compare
|
Rebased on main after #66395 landed, it touched the same lines in @anonrig @gurgunday could one of you start a CI and add commit-queue? |
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, so on Linux nothing change.
Now the deque keeps its storage, like the async_ids_stack_ next to it, which never shrinks.
Until v24 the shrink ran only when the size was over 16 and under half of the capacity, so only after a deep nesting. Since #56457 it runs on every pop.
The same pattern in a small program, on Window with MSVC: 136-147 ns per callback with shrink_to_fit(), 6 ns without. macOS uses libc++, which frees the empty deque in the same way (not measured).
Refs: #66316
Refs: nodejs/performance#24
Disclosure: I used Opus 5.5 (Max) as coding assistant