Prevent timer wheel from growing unexpectedly#238
Merged
notgull merged 3 commits intoSmithay:masterfrom Feb 13, 2026
Merged
Conversation
This was referenced Feb 10, 2026
Member
|
@cmeissl Please rebase on master for CI fixes. |
7f95920 to
1bcd63a
Compare
since rust 1.70 BinaryHeap provides a retain function that can be used to remove our cancelled timers. this prevent indefinitely grow of the heap when timers get cancelled and re-inserted with high frequency.
now that we always clean-up cancelled timers right away there is no longer a need to store the token in an Option.
1bcd63a to
242cfad
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #238 +/- ##
==========================================
+ Coverage 85.47% 86.17% +0.69%
==========================================
Files 14 16 +2
Lines 1825 1997 +172
==========================================
+ Hits 1560 1721 +161
- Misses 265 276 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
done, thanks for taking care of the CI issues! |
Contributor
Author
|
@notgull Do you think it is possible to get a release with the PR applied soon? Looks like quite a lot of people are affected in niri and cosmic-comp by this issue. |
cmeissl
added a commit
to cmeissl/niri
that referenced
this pull request
Feb 13, 2026
this tracks Smithay/calloop#238 which resolves an issue where cancelling timers can result in performance degradation over time and memory buildup
cmeissl
added a commit
to cmeissl/niri
that referenced
this pull request
Feb 13, 2026
this tracks Smithay/calloop#238 which resolves an issue where cancelling timers can result in performance degradation over time and memory buildup
notgull
approved these changes
Feb 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A client cancelling and inserting timers at high rates could result in the used heap to grow unexpectedly.
This can for example happen if a compositor tracks inactivity using a timer and receives a lot of pointer events in a single dispatch.
Currently
TimerWheel::cancelcan result in just marking a timer cancelled without the timer being actually removedfrom the heap. So there might be a time-frame where the heap grows quite big holding mostly cancelled timers.
TimerWheel::next_expiredis expected to clean-up the cancelled timers, but at this point the heap might have alreadygrown quite big and
BinaryHeap::popwill not implicitly shrink its backing store.Also I am not completely sure this will catch all usage patterns as
TimerWheel::insertcould result in re-orderingof the heap.
(Note: Calling shrink might also bring the memory consumption down, but this might result in constant re-allocation)
Calling
TimerWheel::cancelmight already result in linear search in the heap to mark a timer cancelled,so imo using
retaindoes not make this worse but should keep the heap at a reasonable size.This might also have the side-effect of making some operations like next_expired a bit faster for some use-cases.
fixes #233