From 4ebd97b8040cdc1124f648e1cb849e079722bf20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 21 Oct 2025 14:51:21 +0200 Subject: [PATCH] Slightly delay retrieval of working beatmaps in song select panels Beatmap panels can be visible for very brief instants. `PanelSetBackground` has a backstop to prevent expensive background loads which is based on the position of the panel relative to centre of screen. However, retrieving the working beatmap that *precedes* any of that expensive background load logic, is *also* expensive, and *always* runs even if a panel is visible on screen for only a brief second. Therefore, by moving some of that background load delay towards delaying retrieving the working beatmap, we can save on doing even more work, which has beneficial implications for performance. --- osu.Game/Screens/SelectV2/PanelBeatmapSet.cs | 6 +++++- osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs | 6 +++++- osu.Game/Screens/SelectV2/PanelSetBackground.cs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/SelectV2/PanelBeatmapSet.cs b/osu.Game/Screens/SelectV2/PanelBeatmapSet.cs index a52d3fa216..792fa90c4e 100644 --- a/osu.Game/Screens/SelectV2/PanelBeatmapSet.cs +++ b/osu.Game/Screens/SelectV2/PanelBeatmapSet.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; +using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; using osu.Game.Collections; @@ -38,6 +39,7 @@ namespace osu.Game.Screens.SelectV2 private Box chevronBackground = null!; private PanelSetBackground setBackground = null!; + private ScheduledDelegate? scheduledBackgroundRetrieval; private OsuSpriteText titleText = null!; private OsuSpriteText artistText = null!; @@ -191,7 +193,7 @@ namespace osu.Game.Screens.SelectV2 var beatmapSet = groupedBeatmapSet.BeatmapSet; // Choice of background image matches BSS implementation (always uses the lowest `beatmap_id` from the set). - setBackground.Beatmap = beatmaps.GetWorkingBeatmap(beatmapSet.Beatmaps.MinBy(b => b.OnlineID)); + scheduledBackgroundRetrieval = Scheduler.AddDelayed(s => setBackground.Beatmap = beatmaps.GetWorkingBeatmap(s.Beatmaps.MinBy(b => b.OnlineID)), beatmapSet, 50); titleText.Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title); artistText.Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist); @@ -204,6 +206,8 @@ namespace osu.Game.Screens.SelectV2 { base.FreeAfterUse(); + scheduledBackgroundRetrieval?.Cancel(); + scheduledBackgroundRetrieval = null; setBackground.Beatmap = null; updateButton.BeatmapSet = null; difficultiesDisplay.BeatmapSet = null; diff --git a/osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs b/osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs index 4ac05c0308..53ade139e2 100644 --- a/osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs +++ b/osu.Game/Screens/SelectV2/PanelBeatmapStandalone.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Framework.Localisation; +using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; @@ -55,6 +56,7 @@ namespace osu.Game.Screens.SelectV2 private CancellationTokenSource? starDifficultyCancellationSource; private PanelSetBackground beatmapBackground = null!; + private ScheduledDelegate? scheduledBackgroundRetrieval; private OsuSpriteText titleText = null!; private OsuSpriteText artistText = null!; @@ -222,7 +224,7 @@ namespace osu.Game.Screens.SelectV2 var beatmapSet = beatmap.BeatmapSet!; - beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(beatmap); + scheduledBackgroundRetrieval = Scheduler.AddDelayed(b => beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(b), beatmap, 50); titleText.Text = new RomanisableString(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title); artistText.Text = new RomanisableString(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist); @@ -244,6 +246,8 @@ namespace osu.Game.Screens.SelectV2 { base.FreeAfterUse(); + scheduledBackgroundRetrieval?.Cancel(); + scheduledBackgroundRetrieval = null; beatmapBackground.Beatmap = null; updateButton.BeatmapSet = null; localRank.Beatmap = null; diff --git a/osu.Game/Screens/SelectV2/PanelSetBackground.cs b/osu.Game/Screens/SelectV2/PanelSetBackground.cs index 1b49f48ea6..7f15a23b9a 100644 --- a/osu.Game/Screens/SelectV2/PanelSetBackground.cs +++ b/osu.Game/Screens/SelectV2/PanelSetBackground.cs @@ -149,7 +149,7 @@ namespace osu.Game.Screens.SelectV2 // - By using a slightly customised formula to decide when to start the load, we can coerce the loading of backgrounds into an order that // prioritises panels which are closest to the centre of the screen. Basically, we want to load backgrounds "outwards" from the visual // centre to give the user the best experience possible. - float timeUpdatingBeforeLoad = 50 + Math.Abs(containingSsdq.Centre.Y - ScreenSpaceDrawQuad.Centre.Y) / containingSsdq.Height * 100; + float timeUpdatingBeforeLoad = Math.Abs(containingSsdq.Centre.Y - ScreenSpaceDrawQuad.Centre.Y) / containingSsdq.Height * 100; timeSinceUnpool += Time.Elapsed;