-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timers: use Maps for internal duration pooling #11040
Conversation
/cc @mscdex |
IIRC there was some uncertainty surrounding the results of the Map benchmarks some time ago which suggested that they may not actually be as fast as the results were showing. I do not recall the specifics or where the discussion was had, but I'm guessing some thread here on github. I'm concerned about the performance regressions in the other benchmark configurations. I will take a look at this ... |
cc also @misterdjules |
The last time I checked the performance of FWIW I don't think the patterns in EDIT: should be certain arrays of timeouts, like exponential ones. |
Correct. They are not typical. They represent the worst-case scenario. It is important to have that comparison so that we can see how apps in that case could perform.
Pardon? I will note that this change does generally err on the side of improving a worse-case scenario rather than a best-case. |
@Fishrock123 By exponential ones I mean timeouts of |
@joyeecheung Ah, understood. I'm not sure how that would make any difference to the internals compared to what the current (new) benchmarks stress though. |
cc @misterdjules Do you have any thoughts on this one? |
I can more-or-less confirm the benchmark results in the OP. I'm not sure this change is worth it, especially with the perf hit in timers-insert-unpooled.js. Has anyone looked into alternatives such as hierarchical timer wheels (e.g. especially this implementation) or something else? |
I think we should aim to do this if possible, but at the current time I'd prefer to keep this open and try to track why that is when V8 benchmarks appeared to show Maps as faster. (@nodejs/v8)
Yes, quite a lot at the JS layer... As far as I can tell it would be less efficient than what we already have and far more complex. Also, libuv recently-ish stalled moving to timer wheels, see libuv/libuv#823 (comment) and the linked document on why linux core moved away from timer wheels: https://www.kernel.org/doc/Documentation/timers/hrtimers.txt ... Edit: I'd like to add that our average performance is, from what I can tell, better than anything I've seen documented elsewhere, and that our worst-case is also pretty good. (Both of which are |
I read this earlier, which seems to suggest they didn't move away from them, but instead "reinvented" their existing implementation. It looks like this new reinvention eventually made it into the kernel. Even so, I think the tickless timer wheel implementation I linked to previously is interesting and may help (at least design-wise if that particular implementation isn't used as-is) with any perf hit incurred by the need of a continually recurring timer. |
Read through that. Perhaps we could maintain a separate timers impl for that (although I'd prefer not to). The approach seams reasonable for I/O timeouts but I think it would be irresponsible for us to make all user timers use that as beyond a second or so (my estimate, they gave an example into the 17 minute range) the accuracy really starts to drop off and I don't think we could expect user applications to expect that kind of accuracy loss. |
I guess this PR is stalled unless ES maps get sufficiently fast. |
It shouldn't take too terribly long. Map performance is looking rather good under |
I benchmarked this change with 6.0 and it does not look like this has improved at all and the original benefit is gone. I ran this with only 10 runs but I think it is clear that it this is not a improvement. Please note that
@Fishrock123 I think this should be closed? |
Closing due to long inactivity and my current benchmark results. |
The ES benchmarks for maps show it fairly clearly as being faster, and I recall from other places that
Map
s are now supposed to be faster than Object Maps. As such, this PR switches timers' duration pooling to useMap
s.I did some initial benchmarking using the existing timers benchmarks and those from #10925 which came up with some interesting results, but my machine was under other load at the time, so these are inconclusive:
(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), orvcbuild test
(Windows) passesAffected core subsystem(s)
timers