Avoid bindable overheads in OsuHitObject.StackHeight implementation#38162
Open
peppy wants to merge 1 commit into
Open
Avoid bindable overheads in OsuHitObject.StackHeight implementation#38162peppy wants to merge 1 commit into
OsuHitObject.StackHeight implementation#38162peppy wants to merge 1 commit into
Conversation
We made this `HitObjectProperty` class quite a while back with the concept of avoiding bindable initialisation when they are never going to be used. Unfortunately there are multiple cases where bindables are accessed to bind event flows which break this. This one is easy to fix, so I've done so. The other remaining case is more egregious and I can't thing of a ten-minute-fix for it. If anyone has ideas, please take a look: https://github.com/ppy/osu/blob/8b542e5442f42ad132af0414a4f7191df9718a99/osu.Game/Rulesets/Objects/HitObject.cs#L123-L125
Member
Author
bdach
reviewed
Jun 26, 2026
Comment on lines
+88
to
+100
| if (stackHeight.BindableCreated) | ||
| return stackHeight.Bindable; | ||
|
|
||
| stackHeight.Bindable.BindValueChanged(height => | ||
| { | ||
| foreach (var nested in NestedHitObjects) | ||
| { | ||
| if (nested is OsuHitObject osuHitObject) | ||
| osuHitObject.StackHeight = height.NewValue; | ||
| } | ||
| }); | ||
|
|
||
| return stackHeight.Bindable; |
Collaborator
There was a problem hiding this comment.
Let's hope this doesn't get torpedoed by its lack of thread safety I guess? Closest proxy to knowing that is letting CI run, so I'm going to wait for that before clicking any buttons.
Member
Author
There was a problem hiding this comment.
This is where we find out that everything was relying on this being in place to give nested objects correct values.
Collaborator
There was a problem hiding this comment.
diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs
index 0bdbce13d3..0039247eac 100644
--- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs
+++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs
@@ -104,7 +104,19 @@ public Bindable<int> StackHeightBindable
public int StackHeight
{
get => stackHeight.Value;
- set => stackHeight.Value = value;
+ set
+ {
+ stackHeight.Value = value;
+
+ if (!stackHeight.BindableCreated)
+ {
+ foreach (var nested in NestedHitObjects)
+ {
+ if (nested is OsuHitObject osuHitObject)
+ osuHitObject.StackHeight = value;
+ }
+ }
+ }
}
public virtual Vector2 StackOffset => new Vector2(StackHeight * Scale * -6.4f);
fixes the direct failures I guess. If a bit ugly.
Member
Author
There was a problem hiding this comment.
Yeah I'm not sure how far we want to go with this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

We made this
HitObjectPropertyclass quite a while back with the concept of avoiding bindable initialisation when they are never going to be used.Unfortunately there are multiple cases where bindables are accessed to bind event flows which break this.
This one is easy to fix, so I've done so.
The other remaining case is more egregious and I can't thing of a ten-minute-fix for it. If anyone has ideas, please take a look:
osu/osu.Game/Rulesets/Objects/HitObject.cs
Lines 123 to 125 in 8b542e5