Skip to content

perf: single-pass pop_first/pop_last and remove cases 2a/2b#417

Draft
sasa-tomic wants to merge 1 commit intomainfrom
perf/single-pass-pop
Draft

perf: single-pass pop_first/pop_last and remove cases 2a/2b#417
sasa-tomic wants to merge 1 commit intomainfrom
perf/single-pass-pop

Conversation

@sasa-tomic
Copy link
Contributor

@sasa-tomic sasa-tomic commented Mar 18, 2026

Summary

  • Replace double-traversal pop_last/pop_first with single-pass remove_rightmost/remove_leftmost
  • Previously: pop_last called get_max (walks rightmost spine, ~4 node loads) then remove_helper (walks from root again, ~4 more node loads). Now: single descent, handling rotation/merge during the walk
  • Also fixes EXC-1034 TODO in remove_helper cases 2a/2b: replace get_max + remove_helper(predecessor) with remove_rightmost(left_child), and get_min + remove_helper(successor) with remove_leftmost(right_child)

Expected improvement: ~50% fewer load_node calls for pop operations on a depth-4 tree (4 loads vs 8), plus eliminates 4 binary searches per operation.

Replace the double-traversal pattern in pop_first/pop_last with
single-pass remove_leftmost/remove_rightmost methods. Previously,
pop_last would walk the rightmost spine to find the max key (loading
~4 nodes), then walk the same spine again via remove_helper to delete
it (loading ~4 more nodes). The single-pass approach descends once,
handling rebalancing (rotation/merge) during descent.

Also fix the EXC-1034 TODO in remove_helper cases 2a/2b: replace
get_max + remove_helper with remove_rightmost, and get_min +
remove_helper with remove_leftmost.

Expected improvement: ~50% fewer load_node calls for pop operations,
plus eliminates redundant binary searches on the descent path.
@sasa-tomic sasa-tomic requested a review from a team as a code owner March 18, 2026 17:49
@sasa-tomic sasa-tomic marked this pull request as draft March 18, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant