1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Fix performance overhead from ternary state bindable callbacks when selection is changing

Closes https://github.com/ppy/osu/issues/28369.

The reporter of the issue was incorrect; it's not the beat snap grid
that is causing the problem, it's something far stupider than that.

When the current selection changes,
`EditorSelectionHandler.UpdateTernaryStates()` is supposed to update the
state of ternary bindables to reflect the reality of the current
selection. This in turn will fire bindable change callbacks for said
ternary toggles, which heavily use `EditorBeatmap.PerformOnSelection()`.

The thing about that method is that it will attempt to check whether any
changes were actually made to avoid producing empty undo states, *but*
to do this, it must *serialise out the entire beatmap to a stream* and
then *binary equality check that* to determine whether any changes were
actually made:

	7b14c77e43/osu.Game/Screens/Edit/EditorChangeHandler.cs (L65-L69)

As goes without saying, this is very expensive and unnecessary, which
leads to stuff like keeping a selection box active while a taiko beatmap
is playing under it dog slow. So to attempt to mitigate that, add
precondition checks to every single ternary callback of this sort to
avoid this serialisation overhead.

And yes, those precondition checks use linq, and that is *still* faster
than not having them.
This commit is contained in:
Bartłomiej Dach 2024-06-04 10:25:08 +02:00
parent 7b14c77e43
commit f13ca28d5e
No known key found for this signature in database
2 changed files with 18 additions and 0 deletions

View File

@ -53,6 +53,9 @@ namespace osu.Game.Rulesets.Taiko.Edit
public void SetStrongState(bool state) public void SetStrongState(bool state)
{ {
if (SelectedItems.OfType<Hit>().All(h => h.IsStrong == state))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
if (!(h is Hit taikoHit)) return; if (!(h is Hit taikoHit)) return;
@ -67,6 +70,9 @@ namespace osu.Game.Rulesets.Taiko.Edit
public void SetRimState(bool state) public void SetRimState(bool state)
{ {
if (SelectedItems.OfType<Hit>().All(h => h.Type == (state ? HitType.Rim : HitType.Centre)))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
if (h is Hit taikoHit) if (h is Hit taikoHit)

View File

@ -198,6 +198,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="bankName">The name of the sample bank.</param> /// <param name="bankName">The name of the sample bank.</param>
public void AddSampleBank(string bankName) public void AddSampleBank(string bankName)
{ {
if (SelectedItems.All(h => h.Samples.All(s => s.Bank == bankName)))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
if (h.Samples.All(s => s.Bank == bankName)) if (h.Samples.All(s => s.Bank == bankName))
@ -214,6 +217,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="sampleName">The name of the hit sample.</param> /// <param name="sampleName">The name of the hit sample.</param>
public void AddHitSample(string sampleName) public void AddHitSample(string sampleName)
{ {
if (SelectedItems.All(h => h.Samples.Any(s => s.Name == sampleName)))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
// Make sure there isn't already an existing sample // Make sure there isn't already an existing sample
@ -231,6 +237,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="sampleName">The name of the hit sample.</param> /// <param name="sampleName">The name of the hit sample.</param>
public void RemoveHitSample(string sampleName) public void RemoveHitSample(string sampleName)
{ {
if (SelectedItems.All(h => h.Samples.All(s => s.Name != sampleName)))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
h.SamplesBindable.RemoveAll(s => s.Name == sampleName); h.SamplesBindable.RemoveAll(s => s.Name == sampleName);
@ -245,6 +254,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <exception cref="InvalidOperationException">Throws if any selected object doesn't implement <see cref="IHasComboInformation"/></exception> /// <exception cref="InvalidOperationException">Throws if any selected object doesn't implement <see cref="IHasComboInformation"/></exception>
public void SetNewCombo(bool state) public void SetNewCombo(bool state)
{ {
if (SelectedItems.OfType<IHasComboInformation>().All(h => h.NewCombo == state))
return;
EditorBeatmap.PerformOnSelection(h => EditorBeatmap.PerformOnSelection(h =>
{ {
var comboInfo = h as IHasComboInformation; var comboInfo = h as IHasComboInformation;