-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
runtime: improve timer performance #53953
Comments
do you have benchmarks to prove that these will provide real world performance improvements? |
No, but It's not to hard to write some codes. Anyway, as said, It is obvious (in theory) that when we need dereference many timer struct in many location (due to each timer sturct allocate in very different and random memory location) to have a field (here |
I don't quite see how |
I agree with you that in one scenario, It is better to check Timer set to 60 sec later, after 10 sec logic change timer to 120 sec later, after another 10 sec logic change timer to 60 sec later. We change |
When it comes down to it, what matters most is if it improves the performance of real-world programs. You can feel free to implement it and send a PR and try it out, but the decision on whether to merge it is going to come down to actual performance data (though of course if you have any nice cleanups, those would be welcomed on their own). Assigning to you @OmidHekayati for now. |
@OmidHekayati We got to our current approach through a series of real world programs and bug reports that showed bad performance with earlier approaches. I would be quite reluctant to say things like "it is very rare situation that a timer changed more than once before its timerout" or "almost we don't lose anything in this situation." We added the current features because they mattered to real programs, not because we wanted increased complexity. |
@ianlancetaylor You are right, I must choose better words to transfer my thoughts in better way (English is not my native language). I agree with you that no one want to increase complexity for nothing. @mknyszek Thx. I will write some benchmark first to prove the idea and after your approvment, I will take a time to write the actual PR. p.s: Any way I must say that we occur a real problem in one of our project to implement TCP on userspace in Go with millions of timer! So it is very obvious that a little performance improvements can change the game. So this issue is not just hobby for me. |
As you can see our benchmark here, The below result show that when timers allocate in very different memory location with many timers in timing, it is take almost 10X more time to order the timers heap with exiting go runtime library. Some consideration:
Any idea to improve benchmark to cover better real usage?
|
Change https://go.dev/cl/421615 mentions this issue: |
I think it is the time we must close this issue and related PR as It will never ever have chance to merge. I suggest main |
Needed changes to improve performance (At least in theory):
timers []*timer
totimers []timerBucket
when int64
from timer struct in favor oftimerBucket
when field.nextwhen int64
towhen int64
in timer structBy this changes, we claim that we improve performance in
siftupTimer
andsiftdownTimer
when need to compare timers added when to timing heap, we don't need to get data from many different location in the memory (dereference many timers) and we have timers added when in sequential array.Additional suggestions to improve code readability:
timer.go
andtimers.go
in runtime packagetime.go - almost everthing
,proc.go - checkTimers
, ...p.s: If the idea is ok, I can help to make changes by send a PR.
The text was updated successfully, but these errors were encountered: