Skip to content

async_hooks: use resource stack for AsyncLocalStorage run

Rodrigo Muino Tomonari requested to merge github/fork/Qard/als-run-stack into master

Using a stack for AsyncLocalStorage values rather than using AsyncResource instances as containers boosts the performance of the run method by quite a bit. This performance issue actually magnifies when there are many AsyncLocalStorage instances as each will produce its own extra AsyncResource which will trigger all the lifecycle events for every other instance. By eliminating the use of AsyncResource the performance profile should remain relatively flat as instance counts increase.

Before:

% ./node-master benchmark/async_hooks/async-local-storage-run.js            
async_hooks/async-local-storage-run.js n=10000000: 2,524,199.618486664

After:

% ./node benchmark/async_hooks/async-local-storage-run.js       
async_hooks/async-local-storage-run.js n=10000000: 3,467,357.882703789

Merge request reports

Loading