-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5883 from peppy/sprite-text-draw-node-perf
Reduce complexity overhead (and avoid one copy) when obtaining character SSDQs in `SpriteTextDrawNode`
- Loading branch information
Showing
3 changed files
with
131 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Linq; | ||
using BenchmarkDotNet.Attributes; | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Utils; | ||
using osuTK; | ||
|
||
namespace osu.Framework.Benchmarks | ||
{ | ||
public partial class BenchmarkSpriteText : GameBenchmark | ||
{ | ||
private TestGame game = null!; | ||
|
||
[Test] | ||
[Benchmark] | ||
public void TestStaticText() | ||
{ | ||
game.Mode = 0; | ||
RunSingleFrame(); | ||
} | ||
|
||
[Test] | ||
[Benchmark] | ||
public void TestMovingText() | ||
{ | ||
game.Mode = 1; | ||
RunSingleFrame(); | ||
} | ||
|
||
[Test] | ||
[Benchmark] | ||
public void TestChangingText() | ||
{ | ||
game.Mode = 2; | ||
RunSingleFrame(); | ||
} | ||
|
||
protected override Game CreateGame() => game = new TestGame(); | ||
|
||
private partial class TestGame : Game | ||
{ | ||
public int Mode; | ||
|
||
private readonly string text1 = Guid.NewGuid().ToString(); | ||
private readonly string text2 = Guid.NewGuid().ToString(); | ||
|
||
private long frame; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
Add(new SpriteText | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Text = "i am some relatively long text", | ||
}); | ||
} | ||
} | ||
|
||
protected override void Update() | ||
{ | ||
base.Update(); | ||
|
||
switch (Mode) | ||
{ | ||
case 0: | ||
break; | ||
|
||
case 1: | ||
var pos = new Vector2(RNG.NextSingle(100)); | ||
|
||
foreach (var text in Children.OfType<SpriteText>()) | ||
text.Position = pos; | ||
|
||
break; | ||
|
||
case 2: | ||
foreach (var text in Children.OfType<SpriteText>()) | ||
text.Text = frame % 2 == 0 ? text1 : text2; | ||
break; | ||
} | ||
|
||
frame++; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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