⚡ Improve EditorBeatmap.findInsertionIndex performance using binary search - #86
Conversation
Replaces the O(N) linear search with O(log N) binary search for finding insertion indices. Benchmarks show up to ~834x improvement for 10,000 hit objects. | Count | Linear | Binary | |-------|--------|--------| | 100 | 162 ns | 27 ns | | 1000 | 1.6 us | 38 ns | | 10000 | 41 us | 49 ns |
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What
Replaced the linear search implementation in
EditorBeatmap.findInsertionIndexwith a binary search algorithm.🎯 Why
The
findInsertionIndexmethod is called when adding hit objects or tracking their start time changes. With a large number of hit objects (e.g., 10,000+), the linear search (O(N)) becomes a bottleneck during bulk operations or frequent updates. Binary search (O(log N)) significantly reduces the complexity.📊 Measured Improvement
A benchmark was created to measure the performance of
findInsertionIndexwith 100, 1,000, and 10,000 hit objects.For 10,000 objects, the operation is over 800 times faster.
The optimization maintains the original behavior: finding the index of the last element with
StartTime <= targetTime.Tests passed:
osu.Game.Tests.Visual.Editing.TestSceneEditorBeatmaposu.Game.Tests.Editing.TestSceneEditorBeatmapProcessorosu.Game.Tests.Editing.LegacyEditorBeatmapPatcherTestosu.Game.Tests.Visual.Editing.TestSceneEditorBeatmapCreationPR created automatically by Jules for task 18417970512521063628 started by @winnerspiros