What is the overhead of AsyncLocalStorage?
Run the benchmark:
$ npm i benchmark # Run the AsyncLocalStorage benchmark $ node async-local-storage.js ASL ASL x 15,551 ops/sec ±3.30% (79 runs sampled) # Run the witness benchmark $ node async-local-storage.js Witness Witness x 21,352 ops/sec ±1.27% (87 runs sampled)
There is ~25% perf drop by using AsyncLocalStorage
Why you shouldn't use these results to take a decision?
Micro benchmarking is very difficult and also poorly representative of real world situation.
If you want to know if you can afford to use AsyncLocalStorage then you should try it inside you application and run a benchmark before and after.
For example inside Kuzzle the usage of AsyncLocalStorage results in only 8% performance drop
Why I have to run the benchmark separately
I didn't get the same result when I run the benchmarks in the same program.
The second benchmark to run is always slower compare to when I run it by itself.