Skip to content

timers: use Maps for internal duration pooling

The ES benchmarks for maps show it fairly clearly as being faster, and I recall from other places that Maps are now supposed to be faster than Object Maps. As such, this PR switches timers' duration pooling to use Maps.

I did some initial benchmarking using the existing timers benchmarks and those from https://github.com/nodejs/node/pull/10925 which came up with some interesting results, but my machine was under other load at the time, so these are inconclusive:

                                                    improvement confidence      p.value
 timers/timers-breadth.js thousands=500                 -5.31 %        *** 4.071485e-06
 timers/timers-cancel-pooled.js thousands=500           -2.85 %         ** 1.209156e-03
 timers/timers-cancel-unpooled.js thousands=100       1507.75 %        *** 1.664058e-42
 timers/timers-depth.js thousands=1                      0.03 %            8.551970e-01
 timers/timers-insert-pooled.js thousands=500           -4.03 %        *** 1.004463e-06
 timers/timers-insert-unpooled.js thousands=100        -28.91 %        *** 4.867811e-38

(This patch was made live during https://www.twitch.tv/videos/117984923 if you'd like to see me working on this in retrospect. :P)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

timers

Merge request reports

Loading