Skip to content

Conversation

@bdach
Copy link
Collaborator

@bdach bdach commented Oct 22, 2025

RFC. Maybe addresses some of #34843.

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 - which is done only for the purposes of displaying the backgrounds, and that precedes any of that expensive background load logic - is also expensive because realm detaches are expensive due to deep cloning via automapper, 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.

There's no great way to show profiling results for this, as the hopeful result is the decreased count of calls to GetWorkingBeatmap(), which is a bit tricky to demonstrate when spamming F2 because how many retrievals happen depends on pure chance.

This doesn't specifically impact standalone panels, which is why the commit also touches set panels, but is more noticeable on standalone panels because there are more panels with backgrounds in these cases.

Fix performance overhead when computing spacing between standalone panels

The equality check that was supposed to replace the read of CurrentSelectionItem (see a3db764) showed up as a hotspot in profiling.

The selection updating code looks a little stupid after this, but all in the name of performance...

before after
Screenshot 2025-10-22 at 12 00 55 Screenshot 2025-10-22 at 12 01 28

bdach added 2 commits October 22, 2025 11:00
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.
…nels

The equality check that was supposed to replace the read of
`CurrentSelectionItem` showed up as a hotspot in profiling.

The selection updating code looks a little stupid after this, but all in
the name of performance...
@bdach bdach requested a review from peppy October 22, 2025 10:17
@bdach bdach self-assigned this Oct 22, 2025
@bdach bdach added the type/performance Deals with performance regressions or fixes without changing functionality. label Oct 22, 2025
@bdach bdach moved this from Next up to Pending Review in osu! untitled project Oct 22, 2025
var beatmapSet = beatmap.BeatmapSet!;

beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(beatmap);
scheduledBackgroundRetrieval = Scheduler.AddDelayed(b => beatmapBackground.Beatmap = beatmaps.GetWorkingBeatmap(b), beatmap, 50);
Copy link
Member

Choose a reason for hiding this comment

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

I remember testing this during original implementation but I couldn't see the overhead. I may have been incorrectly testing though, as working beatmaps do get cached after first load.

(And I guess that's one thing to note here – this is delayed the load even when they are cached already. Shouldn't change anything since you've just moved the delay from elsewhere, though.)

{
var item = carouselItems[i];

bool isKeyboardSelection = CheckModelEquality(item.Model, currentKeyboardSelection.Model!);
Copy link
Member

Choose a reason for hiding this comment

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

A bit awkward but worth it for the huge performance boost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:song-select size/M type/performance Deals with performance regressions or fixes without changing functionality.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants