Skip to content
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

Improve song select search performance #25679

Merged
merged 5 commits into from
Dec 5, 2023

Conversation

peppy
Copy link
Member

@peppy peppy commented Dec 5, 2023

Just a quick optimisation pass. Anything further will require more consideration, as the overhead is coming from the raw IndexTo operation, and to a lesser extent CarouselBeatmap.checkMatch() and other methods with nothing too simple to optimise out:

CleanShot 2023-12-05 at 06 32 00

Initial filter is the full load of song select (includes sort). Subsequent are filtering on non-matching strings (ie. "aaaaaaa").

master:

[runtime] 2023-12-05 05:23:02 [verbose]: Filter took 8,785.0 ms
[runtime] 2023-12-05 05:23:39 [verbose]: Filter took 9,147.0 ms
[runtime] 2023-12-05 05:23:50 [verbose]: Filter took 9,159.0 ms
[runtime] 2023-12-05 05:24:00 [verbose]: Filter took 9,254.0 ms
[runtime] 2023-12-05 05:24:16 [verbose]: Filter took 9,474.0 ms

after 7fda38d:

[runtime] 2023-12-05 05:20:36 [verbose]: Filter took 8,739.0 ms
[runtime] 2023-12-05 05:21:40 [verbose]: Filter took 6,354.0 ms
[runtime] 2023-12-05 05:21:47 [verbose]: Filter took 6,471.0 ms
[runtime] 2023-12-05 05:21:53 [verbose]: Filter took 6,437.0 ms
[runtime] 2023-12-05 05:22:02 [verbose]: Filter took 6,753.0 ms

after 27e778a:

[runtime] 2023-12-05 05:18:30 [verbose]: Filter took 8,990.0 ms
[runtime] 2023-12-05 05:19:15 [verbose]: Filter took 1,266.0 ms
[runtime] 2023-12-05 05:19:17 [verbose]: Filter took 1,213.0 ms
[runtime] 2023-12-05 05:19:19 [verbose]: Filter took 1,179.0 ms
[runtime] 2023-12-05 05:19:21 [verbose]: Filter took 1,166.0 ms

after 36eb338:

[runtime] 2023-12-05 05:54:19 [verbose]: Filter took 8,789.0 ms
[runtime] 2023-12-05 05:54:41 [verbose]: Filter took 1,232.0 ms
[runtime] 2023-12-05 05:54:43 [verbose]: Filter took 1,061.0 ms
[runtime] 2023-12-05 05:54:44 [verbose]: Filter took 1,039.0 ms
[runtime] 2023-12-05 05:54:46 [verbose]: Filter took 1,032.0 ms

Testing done using:

diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs
index eb47a7201a..53bfef7d87 100644
--- a/osu.Game/Screens/Select/BeatmapCarousel.cs
+++ b/osu.Game/Screens/Select/BeatmapCarousel.cs
@@ -17,6 +17,7 @@
 using osu.Framework.Input.Bindings;
 using osu.Framework.Input.Events;
 using osu.Framework.Layout;
+using osu.Framework.Logging;
 using osu.Framework.Threading;
 using osu.Framework.Utils;
 using osu.Game.Beatmaps;
@@ -131,6 +132,9 @@ private void loadBeatmapSets(IEnumerable<BeatmapSetInfo> beatmapSets)
         {
             originalBeatmapSetsDetached = beatmapSets.Detach();
 
+            while (originalBeatmapSetsDetached.Count < 250000)
+                originalBeatmapSetsDetached.AddRange(originalBeatmapSetsDetached);
+
             if (selectedBeatmapSet != null && !originalBeatmapSetsDetached.Contains(selectedBeatmapSet.BeatmapSet))
                 selectedBeatmapSet = null;
 
@@ -738,6 +742,9 @@ void perform()
                     return;
                 }
 
+                Stopwatch sw = new Stopwatch();
+                sw.Start();
+
                 root.Filter(activeCriteria);
                 itemsCache.Invalidate();
 
@@ -745,6 +752,8 @@ void perform()
                     ScrollToSelected(true);
 
                 FilterApplied?.Invoke();
+
+                Logger.Log($"Filter took {sw.ElapsedMilliseconds:N1} ms");
             }
         }
 

Improves #11571 but probably doesn't close yet (would want things to be async still).


Reduces time taken to search beatmaps at song select by 88%.

Bypasses various overheads. In theory should be fine? (until it's not on some language)
Very minor, but putting the more common case towards the
start of the method allows early return.
osu.Game/Beatmaps/BeatmapInfoExtensions.cs Outdated Show resolved Hide resolved
osu.Game/Beatmaps/BeatmapInfoExtensions.cs Show resolved Hide resolved
@bdach bdach merged commit 566d336 into ppy:master Dec 5, 2023
13 of 17 checks passed
@peppy peppy deleted the song-select-search-performance branch December 6, 2023 02:04
peppy added a commit to peppy/osu that referenced this pull request Dec 6, 2023
peppy added a commit to peppy/osu that referenced this pull request Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants