Repository navigation
perf: Utilize Maps for metric collection - #658
Conversation
|
Thanks for digging into it! I'm fine with making a major release dropping node 16&18 and this API change 👍 |
|
This still works on node 16. It’s just that the numbers are less impressive. |
9f26080 to
27b4f7f
Compare
|
I got warnings about a CI error as email, but I'm not seeing them here in the PR. Shouldn't they be listed here as well? |
|
I just approved the workflow run. Do you see the errors here now? Looks good to me once the two failed checks are resolved. |
|
Sure. Are you running different eslint settings that “test”? Thought I already caught these. |
I'm getting absolutely nothing. |
As of Node ~16, maps are constently faster than DIY maps, particularly so with objects that will grow or shrink over their lifetimes. On another project I saw an almost 40% reduction in heap size for a large lookup table and about a 5% reduction in response time for the entire workflow (not just the cache)
|
One last CI error to fix. |
These are faster than constantly changing {} instances since
sometime in Node 16 and got faster still in Node 18
|
Well that one was just sloppiness. Fixed. |
As of sometime around the middle of Node 16, the performance of Map for long-lived, mutable objects exceeded that of {}. I believe this gap is more pronounced in Node 18 as well.
The deal is that the representation for Objects that repeatedly change turns into a weird chain that occupies (in my benchmarks at least) ~40% more memory. So once v8 made Map.set/get faster than map[], we all should have switched to Maps and Sets.
Between the slightly faster functions and the lower memory pressure this can create a notable improvement.
Making a change like this on my last project for a long lived cache resulted in much better memory behavior and also about a 5% improvement in TTFB - just from changing a popular lookup table.
Note that the final change in this PR constitutes a change for anyone making their own subclasses, and therefore is probably breaking. Let me know if you want me to split this into two PRs, but that's where the bulk of the changes show up. The Registry just doesn't change frequently enough.