From c2de03aa44c85fccb29e5542c63c01d46dc7145d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 1 Nov 2023 18:28:05 +0900 Subject: [PATCH 1/2] Fix all spinner ticks being alive and causing performance degradation Regressed in https://github.com/ppy/osu/pull/25216. The new logic will ensure at least one tick is ready for judgement. There shouldn't be a case where more than one is needed in a single frame. --- .../Objects/Drawables/DrawableSpinner.cs | 13 +++++++++++++ .../Objects/Drawables/DrawableSpinnerTick.cs | 8 ++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index c092b4dd4b..2799ba4a25 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -275,6 +275,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables if (spinningSample != null && spinnerFrequencyModulate) spinningSample.Frequency.Value = spinning_sample_modulated_base_frequency + Progress; + + // Ticks can theoretically be judged at any point in the spinner's duration. + // For performance reasons, we only want to keep the next tick alive. + var next = NestedHitObjects.FirstOrDefault(h => !h.Judged); + + // See default `LifetimeStart` as set in `DrawableSpinnerTick`. + if (next?.LifetimeStart == double.MaxValue) + { + // the tick can be theoretically judged at any point in the spinner's duration, + // so it must be alive throughout the spinner's entire lifetime. + // this mostly matters for correct sample playback. + next.LifetimeStart = HitObject.StartTime; + } } protected override void UpdateAfterChildren() diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinnerTick.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinnerTick.cs index a5785dd1f6..5b55533edd 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinnerTick.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinnerTick.cs @@ -11,8 +11,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { public override bool DisplayResult => false; - protected DrawableSpinner DrawableSpinner => (DrawableSpinner)ParentHitObject; - public DrawableSpinnerTick() : this(null) { @@ -29,10 +27,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { base.OnApply(); - // the tick can be theoretically judged at any point in the spinner's duration, - // so it must be alive throughout the spinner's entire lifetime. - // this mostly matters for correct sample playback. - LifetimeStart = DrawableSpinner.HitObject.StartTime; + // Lifetime will be managed by `DrawableSpinner`. + LifetimeStart = double.MaxValue; } /// From ad82ada030715427397d6ef5b0a08b475dbfef31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 2 Nov 2023 08:18:37 +0100 Subject: [PATCH 2/2] Trim redundant comments --- .../Objects/Drawables/DrawableSpinner.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 2799ba4a25..2e9a4d92ec 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -277,17 +277,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables spinningSample.Frequency.Value = spinning_sample_modulated_base_frequency + Progress; // Ticks can theoretically be judged at any point in the spinner's duration. - // For performance reasons, we only want to keep the next tick alive. + // A tick must be alive to correctly play back samples, + // but for performance reasons, we only want to keep the next tick alive. var next = NestedHitObjects.FirstOrDefault(h => !h.Judged); // See default `LifetimeStart` as set in `DrawableSpinnerTick`. if (next?.LifetimeStart == double.MaxValue) - { - // the tick can be theoretically judged at any point in the spinner's duration, - // so it must be alive throughout the spinner's entire lifetime. - // this mostly matters for correct sample playback. next.LifetimeStart = HitObject.StartTime; - } } protected override void UpdateAfterChildren()