-
Notifications
You must be signed in to change notification settings - Fork 698
Don't re-arm timerfd each epoll_wait #264
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
Conversation
I need to write a few tests but the idea is the same as: |
0205ccd
to
7ae80fe
Compare
7ae80fe
to
0b2ab4d
Compare
Test added PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'm happy with this.
Sources/NIO/Selector.swift
Outdated
// expensive. | ||
let next = DispatchTime.now().uptimeNanoseconds + UInt64(timeAmount.nanoseconds) | ||
if next < earliestTimer { | ||
earliestTimer = next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, please use explicit self's on
earliestTimer`. It'll help make this a lot clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Motivation: When calling Selector.whenReady(...) and using a SelectorStrategy.blockUntil(...) we may end up re-arm the timerfd each time even if the wakeup time did not change. This is expensive and can be avoided in most situations. Modifications: Keep track of the earliest scheduled timer and only schedule a new one if it would fire sooner. Result: Less overhead when using epoll and timers.
0b2ab4d
to
0c7c131
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'm happy. Will wait for @weissi to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, lgtm!
Motivation:
When calling Selector.whenReady(...) and using a SelectorStrategy.blockUntil(...) we may end up re-arm the timerfd each time even if the wakeup time did not change.
This is expensive and can be avoided in most situations.
Modifications:
Keep track of the earliest scheduled timer and only schedule a new one if it would fire sooner.
Result:
Less overhead when using epoll and timers.