Skip to content

perf(runtime): drain due timers with extract_if instead of split_off - #1072

Merged
Berrysoft merged 1 commit into
compio-rs:masterfrom
lvella:timer-extract-if
Sep 27, 2026
Merged

Berrysoft merged 1 commit into
compio-rs:masterfrom
lvella:timer-extract-if

Conversation

@lvella

@lvella lvella commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Despite both extract_if and split_off being O(log N) on the number of active timers, split_off is a much heavier operation that performs a number of allocations before even starting the search. It creates a measurable cost per ticks on the scale of thousands of running timers.

extract_if is just one O(log N) search for the smallest key, then O(1) sibling walk on the tree.

AI disclaimer: AI was used to pin down the cost increase with running timers, analyzed split_off implementation and suggested the use of extract_if instead.

Despite both extract_if and split_off being O(log N) on the number
of active timers, split_off is a much heavier operation that performs
a number of allocations before even starting the search. It creates
a measurable cost per ticks on the scale of thousands of running timers.

extract_if is just one O(log N) search for the smallest key, then
O(1) sibling walk on the tree.

AI disclaimer: AI was used to pin down the cost increase with running
timers, analyzed split_off implementation and suggested the use of
extract_if instead.
@github-actions github-actions Bot added package: runtime Related to compio-runtime performance Performance related (regression/optimization) labels Sep 25, 2026

@Berrysoft Berrysoft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@Berrysoft
Berrysoft merged commit 46bdd1b into compio-rs:master Sep 27, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: runtime Related to compio-runtime performance Performance related (regression/optimization)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants