Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy init AudioAdjustments in AdjustableAudioComponent usage #5532

Merged
merged 2 commits into from
Nov 22, 2022

Conversation

peppy
Copy link
Member

@peppy peppy commented Nov 22, 2022

This is beneficial due to the number of samples which are retrieves during BDL load but never played. In cases they aren't played the Samples retrieved from a SampleFactory can avoid the AudioAdjustments overhead, which will now only be instantiated when they are played (see

public Sample CreateSample() => new SampleBass(this, mixer) { OnPlay = onPlay };
private void onPlay(Sample sample)
{
AddItem(sample);
}
)

Logging can be performed using this adjustment:

diff --git a/osu.Framework/Audio/AdjustableAudioComponent.cs b/osu.Framework/Audio/AdjustableAudioComponent.cs
index 41b834da0..f5813a763 100644
--- a/osu.Framework/Audio/AdjustableAudioComponent.cs
+++ b/osu.Framework/Audio/AdjustableAudioComponent.cs
@@ -2,6 +2,7 @@
 // See the LICENCE file in the repository root for full licence text.
 
 using osu.Framework.Bindables;
+using osu.Framework.Statistics;
 
 namespace osu.Framework.Audio
 {
@@ -60,8 +61,16 @@ protected internal AudioAdjustments Adjustments
         /// </summary>
         public BindableNumber<double> Tempo => Adjustments.Tempo;
 
-        public void AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable) =>
+        protected AdjustableAudioComponent()
+        {
+            GlobalStatistics.Get<int>("audio", "aac instantiated").Value++;
+        }
+
+        public void AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable)
+        {
+            logAdjustment();
             Adjustments.AddAdjustment(type, adjustBindable);
+        }
 
         public void RemoveAdjustment(AdjustableProperty type, IBindable<double> adjustBindable) =>
             Adjustments.RemoveAdjustment(type, adjustBindable);
@@ -95,6 +104,7 @@ protected override void UpdateState()
 
         public void BindAdjustments(IAggregateAudioAdjustment component)
         {
+            logAdjustment();
             Adjustments.BindAdjustments(component);
         }
 
@@ -108,6 +118,17 @@ public void BindAdjustments(IAggregateAudioAdjustment component)
 
         public IBindable<double> AggregateTempo => Adjustments.AggregateTempo;
 
+        private bool wasAdjusted;
+
+        private void logAdjustment()
+        {
+            if (wasAdjusted)
+                return;
+
+            GlobalStatistics.Get<int>("audio", "aac bound").Value++;
+            wasAdjusted = true;
+        }
+
         protected override void Dispose(bool disposing)
         {
             base.Dispose(disposing);

At song select:

osu! 2022-11-22 at 05 27 57

Before:

JetBrains Rider-EAP 2022-11-22 at 05 33 42

JetBrains Rider-EAP 2022-11-22 at 05 34 16

After:

JetBrains Rider-EAP 2022-11-22 at 05 30 53

JetBrains Rider-EAP 2022-11-22 at 05 35 59

Note that there are other potential areas that could also fix this (ie. stopping every single instance of HoverClickSounds from fetching its own samples osu! side) but I feel this is beneficial to also optimise at a lower level, since retrieving samples from a SampleStore for (potential) future use is a common one.

@smoogipoo smoogipoo enabled auto-merge November 22, 2022 06:34
@smoogipoo smoogipoo merged commit b72131c into ppy:master Nov 22, 2022
@peppy peppy deleted the lazy-init-audio-adjustments branch November 25, 2022 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants