Skip to content

Commit

Permalink
Do not regenerate breaks unless meaningful change to object start/end…
Browse files Browse the repository at this point in the history
… times is detected

Tangentially found when profiling #28792.

For reproduction, import https://osu.ppy.sh/beatmapsets/972#osu/9007,
move any object on the playfield, and observe a half-second freeze
when ending the drag.
  • Loading branch information
bdach committed Jul 10, 2024
1 parent 13c8370 commit 343090e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions osu.Game/Screens/Edit/EditorBeatmapProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
Expand All @@ -18,6 +19,11 @@ public class EditorBeatmapProcessor : IBeatmapProcessor

private readonly IBeatmapProcessor? rulesetBeatmapProcessor;

/// <summary>
/// Kept for the purposes of reducing redundant regeneration of automatic breaks.
/// </summary>
private HashSet<(double, double)> objectDurationCache = new HashSet<(double, double)>();

public EditorBeatmapProcessor(EditorBeatmap beatmap, Ruleset ruleset)
{
Beatmap = beatmap;
Expand All @@ -38,6 +44,13 @@ public void PostProcess()

private void autoGenerateBreaks()
{
var objectDuration = Beatmap.HitObjects.Select(ho => (ho.StartTime, ho.GetEndTime())).ToHashSet();

if (objectDuration.SetEquals(objectDurationCache))
return;

objectDurationCache = objectDuration;

Beatmap.Breaks.RemoveAll(b => b is not ManualBreakPeriod);

foreach (var manualBreak in Beatmap.Breaks.ToList())
Expand Down

0 comments on commit 343090e

Please sign in to comment.