Fix performance overhead from ternary state bindable callbacks when selection is changing #28387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RFC.
Closes #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 useEditorBeatmap.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:
osu/osu.Game/Screens/Edit/EditorChangeHandler.cs
Lines 65 to 69 in 7b14c77
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.