Skip to content

Commit 82f37c8

Browse files
authored
Merge pull request #6521 from peppy/async-disposal-fix
Reduce overhead of async disposal
2 parents 87dc5a6 + e1b28eb commit 82f37c8

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using System.Collections.Generic;
5+
using BenchmarkDotNet.Attributes;
6+
using NUnit.Framework;
7+
using osu.Framework.Allocation;
8+
using osu.Framework.Graphics;
9+
using osu.Framework.Graphics.Shapes;
10+
11+
namespace osu.Framework.Benchmarks
12+
{
13+
[MemoryDiagnoser]
14+
public partial class BenchmarkAsyncDisposal
15+
{
16+
private readonly List<Drawable> objects = new List<Drawable>();
17+
18+
[GlobalSetup]
19+
[OneTimeSetUp]
20+
public virtual void SetUp()
21+
{
22+
objects.Clear();
23+
for (int i = 0; i < 10000; i++)
24+
objects.Add(new Box());
25+
}
26+
27+
[Test]
28+
[Benchmark]
29+
public void Run()
30+
{
31+
objects.ForEach(AsyncDisposalQueue.Enqueue);
32+
AsyncDisposalQueue.WaitForEmpty();
33+
}
34+
}
35+
}

osu.Framework/Allocation/AsyncDisposalQueue.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace osu.Framework.Allocation
1717
/// </summary>
1818
internal static class AsyncDisposalQueue
1919
{
20-
private static readonly GlobalStatistic<string> last_disposal = GlobalStatistics.Get<string>("Drawable", "Last disposal");
20+
private static readonly GlobalStatistic<Type> last_disposal = GlobalStatistics.Get<Type>("Drawable", "Last disposal");
2121

2222
private static Task runTask;
2323

@@ -62,7 +62,7 @@ public static void Enqueue(IDisposable disposable)
6262
{
6363
ref var item = ref itemsToDispose[i];
6464

65-
last_disposal.Value = item.ToString();
65+
last_disposal.Value = item.GetType();
6666

6767
item.Dispose();
6868
item = null;

osu.Framework/Statistics/GlobalStatistic.cs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
#nullable disable
55

6+
using System;
7+
using osu.Framework.Extensions.TypeExtensions;
8+
69
namespace osu.Framework.Statistics
710
{
811
public class GlobalStatistic<T> : IGlobalStatistic
@@ -23,6 +26,9 @@ public string DisplayValue
2326
{
2427
switch (Value)
2528
{
29+
case Type t:
30+
return t.ReadableName();
31+
2632
case double d:
2733
return d.ToString("#,0.##");
2834

0 commit comments

Comments
 (0)