osu/osu.Desktop/Performance/HighPerformanceSessionManag...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.4 KiB
C#
Raw Normal View History

// 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.Runtime;
using osu.Framework.Allocation;
2024-02-27 10:17:34 +00:00
using osu.Framework.Logging;
2024-02-27 10:36:03 +00:00
using osu.Game.Performance;
2024-02-27 10:36:03 +00:00
namespace osu.Desktop.Performance
{
2024-02-27 10:36:03 +00:00
public class HighPerformanceSessionManager : IHighPerformanceSessionManager
{
private GCLatencyMode originalGCMode;
public IDisposable BeginSession()
{
2024-02-27 08:33:24 +00:00
enableHighPerformanceSession();
return new InvokeOnDisposal<HighPerformanceSessionManager>(this, static m => m.disableHighPerformanceSession());
}
2024-02-27 08:33:24 +00:00
private void enableHighPerformanceSession()
{
2024-02-27 10:17:34 +00:00
Logger.Log("Starting high performance session");
originalGCMode = GCSettings.LatencyMode;
GCSettings.LatencyMode = GCLatencyMode.LowLatency;
// Without doing this, the new GC mode won't kick in until the next GC, which could be at a more noticeable point in time.
GC.Collect(0);
}
2024-02-27 08:33:24 +00:00
private void disableHighPerformanceSession()
{
2024-02-27 10:17:34 +00:00
Logger.Log("Ending high performance session");
if (GCSettings.LatencyMode == GCLatencyMode.LowLatency)
GCSettings.LatencyMode = originalGCMode;
// No GC.Collect() as we were already collecting at a higher frequency in the old mode.
}
}
}