From f39ab028a7365fbb881d165e7dcccb642da1284d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Jul 2022 02:52:43 +0900 Subject: [PATCH 1/4] Reduce overhead of transform processing when no transforms are present in a drawable Before: | Method | Mean | Error | StdDev | Allocated | |-------------------------------- |---------:|--------:|--------:|----------:| | UpdateTransformsWithNonePresent | 101.2 us | 0.31 us | 0.25 us | - | | UpdateTransformsWithManyPresent | 383.3 us | 2.21 us | 2.07 us | 1 B | After: | Method | Mean | Error | StdDev | Allocated | |-------------------------------- |-----------:|----------:|----------:|----------:| | UpdateTransformsWithNonePresent | 5.091 us | 0.0303 us | 0.0269 us | - | | UpdateTransformsWithManyPresent | 353.660 us | 6.8759 us | 9.6390 us | 1 B | --- .../Graphics/Transforms/Transformable.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/osu.Framework/Graphics/Transforms/Transformable.cs b/osu.Framework/Graphics/Transforms/Transformable.cs index ca697b0217..9fbf8e69b0 100644 --- a/osu.Framework/Graphics/Transforms/Transformable.cs +++ b/osu.Framework/Graphics/Transforms/Transformable.cs @@ -42,7 +42,7 @@ public abstract class Transformable : ITransformable /// /// A lazily-initialized list of s applied to this object. /// - public IEnumerable Transforms => targetGroupingTrackers.SelectMany(t => t.Transforms); + public IEnumerable Transforms => targetGroupingTrackers?.SelectMany(t => t.Transforms) ?? Array.Empty(); /// /// Retrieves the s for a given target member. @@ -63,13 +63,16 @@ public double LatestTransformEndTime //expiry should happen either at the end of the last transform or using the current sequence delay (whichever is highest). double max = TransformStartTime; - foreach (var tracker in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - for (int i = 0; i < tracker.Transforms.Count; i++) + foreach (var tracker in targetGroupingTrackers) { - var t = tracker.Transforms[i]; - if (t.EndTime > max) - max = t.EndTime + 1; //adding 1ms here ensures we can expire on the current frame without issue. + for (int i = 0; i < tracker.Transforms.Count; i++) + { + var t = tracker.Transforms[i]; + if (t.EndTime > max) + max = t.EndTime + 1; //adding 1ms here ensures we can expire on the current frame without issue. + } } } @@ -88,15 +91,22 @@ public double LatestTransformEndTime protected void UpdateTransforms() { TransformDelay = 0; + + if (targetGroupingTrackers == null) + return; + updateTransforms(Time.Current); } private double lastUpdateTransformsTime; - private readonly List targetGroupingTrackers = new List(); + private List targetGroupingTrackers; private TargetGroupingTransformTracker getTrackerFor(string targetMember) { + if (targetGroupingTrackers == null) + return null; + foreach (var t in targetGroupingTrackers) { if (t.TargetMembers.Contains(targetMember)) @@ -108,6 +118,8 @@ private TargetGroupingTransformTracker getTrackerFor(string targetMember) private TargetGroupingTransformTracker getTrackerForGrouping(string targetGrouping, bool createIfNotExisting) { + targetGroupingTrackers ??= new List(); + foreach (var t in targetGroupingTrackers) { if (t.TargetGrouping == targetGrouping) @@ -130,6 +142,9 @@ private TargetGroupingTransformTracker getTrackerForGrouping(string targetGroupi /// Whether prior transforms should be reprocessed even if a rewind was not detected. private void updateTransforms(double time, bool forceRewindReprocess = false) { + if (targetGroupingTrackers == null) + return; + bool rewinding = lastUpdateTransformsTime > time || forceRewindReprocess; lastUpdateTransformsTime = time; @@ -179,6 +194,9 @@ public virtual void ClearTransformsAfter(double time, bool propagateChildren = f { EnsureTransformMutationAllowed(); + if (targetGroupingTrackers == null) + return; + if (targetMember != null) { getTrackerFor(targetMember)?.ClearTransformsAfter(time, targetMember); @@ -220,6 +238,9 @@ public virtual void FinishTransforms(bool propagateChildren = false, string targ { EnsureTransformMutationAllowed(); + if (targetGroupingTrackers == null) + return; + if (targetMember != null) { getTrackerFor(targetMember)?.FinishTransforms(targetMember); From cdb3dc93851638bb6f721c302d5237e366258fc0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Jul 2022 03:17:45 +0900 Subject: [PATCH 2/4] Add benchmark of updating transforms when none are added --- osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs b/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs index 6bebf443a6..7b351067f8 100644 --- a/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs +++ b/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs @@ -14,6 +14,7 @@ namespace osu.Framework.Benchmarks public class BenchmarkTransformUpdate : BenchmarkTest { private TestBox target; + private TestBox targetNoTransforms; public override void SetUp() { @@ -23,7 +24,8 @@ public override void SetUp() ManualClock clock; - target = new TestBox { Clock = new FramedClock(clock = new ManualClock()) }; + targetNoTransforms = new TestBox { Clock = new FramedClock(clock = new ManualClock()) }; + target = new TestBox { Clock = new FramedClock(clock) }; // transform one target member over a long period target.RotateTo(360, transforms_count * 2); @@ -36,6 +38,13 @@ public override void SetUp() target.Clock.ProcessFrame(); } + [Benchmark] + public void UpdateTransformsWithNonePresent() + { + for (int i = 0; i < 10000; i++) + targetNoTransforms.UpdateTransforms(); + } + [Benchmark] public void UpdateTransformsWithManyPresent() { From ff44ed7c5cd8676c24ad87a48365f738c3ea3170 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 1 Jul 2022 12:12:31 +0900 Subject: [PATCH 3/4] Reoganise ordering/nested to be more consistent over applications --- .../Graphics/Transforms/Transformable.cs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/osu.Framework/Graphics/Transforms/Transformable.cs b/osu.Framework/Graphics/Transforms/Transformable.cs index 9fbf8e69b0..ca62a1f8c0 100644 --- a/osu.Framework/Graphics/Transforms/Transformable.cs +++ b/osu.Framework/Graphics/Transforms/Transformable.cs @@ -104,13 +104,13 @@ protected void UpdateTransforms() private TargetGroupingTransformTracker getTrackerFor(string targetMember) { - if (targetGroupingTrackers == null) - return null; - - foreach (var t in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - if (t.TargetMembers.Contains(targetMember)) - return t; + foreach (var t in targetGroupingTrackers) + { + if (t.TargetMembers.Contains(targetMember)) + return t; + } } return null; @@ -118,19 +118,23 @@ private TargetGroupingTransformTracker getTrackerFor(string targetMember) private TargetGroupingTransformTracker getTrackerForGrouping(string targetGrouping, bool createIfNotExisting) { - targetGroupingTrackers ??= new List(); - - foreach (var t in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - if (t.TargetGrouping == targetGrouping) - return t; + foreach (var t in targetGroupingTrackers) + { + if (t.TargetGrouping == targetGrouping) + return t; + } } if (!createIfNotExisting) return null; var tracker = new TargetGroupingTransformTracker(this, targetGrouping); + + targetGroupingTrackers ??= new List(); targetGroupingTrackers.Add(tracker); + return tracker; } @@ -192,11 +196,11 @@ public virtual void ClearTransforms(bool propagateChildren = false, string targe /// public virtual void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null) { - EnsureTransformMutationAllowed(); - if (targetGroupingTrackers == null) return; + EnsureTransformMutationAllowed(); + if (targetMember != null) { getTrackerFor(targetMember)?.ClearTransformsAfter(time, targetMember); @@ -236,11 +240,11 @@ public virtual void ApplyTransformsAt(double time, bool propagateChildren = fals /// public virtual void FinishTransforms(bool propagateChildren = false, string targetMember = null) { - EnsureTransformMutationAllowed(); - if (targetGroupingTrackers == null) return; + EnsureTransformMutationAllowed(); + if (targetMember != null) { getTrackerFor(targetMember)?.FinishTransforms(targetMember); From 35c4ee39f2c6c5a5fda220e7bb139c3dbc825e72 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 1 Jul 2022 11:16:44 +0300 Subject: [PATCH 4/4] Remove iOS build CI workaround --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccfc888032..e7e7ba5fe7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,12 +126,6 @@ jobs: with: dotnet-version: "6.0.x" - # macOS agents recently have empty NuGet config files, resulting in restore failures, - # see https://github.com/actions/virtual-environments/issues/5768 - # Add the global nuget package source manually for now. - - name: Setup NuGet.Config - run: echo '' > ~/.config/NuGet/NuGet.Config - # Contrary to seemingly any other msbuild, msbuild running on macOS/Mono # cannot accept .sln(f) files as arguments. # Build just the iOS framework project for now.