diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 9ffa88947b..f23a78d2dc 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -792,7 +792,7 @@ public override Task Import(ImportTask[] imports, ImportParameters parameters = protected virtual UpdateManager CreateUpdateManager() => new UpdateManager(); - protected virtual HighPerformanceSession CreateHighPerformanceSession() => new HighPerformanceSession(); + protected virtual HighPerformanceSessionManager CreateHighPerformanceSessionManager() => new HighPerformanceSessionManager(); protected override Container CreateScalingContainer() => new ScalingContainer(ScalingMode.Everything); @@ -1088,7 +1088,7 @@ protected override void LoadComplete() loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true); loadComponentSingleFile(new DialogOverlay(), topMostOverlayContent.Add, true); - loadComponentSingleFile(CreateHighPerformanceSession(), Add); + loadComponentSingleFile(CreateHighPerformanceSessionManager(), Add, true); loadComponentSingleFile(new BackgroundDataStoreProcessor(), Add); diff --git a/osu.Game/Performance/HighPerformanceSession.cs b/osu.Game/Performance/HighPerformanceSession.cs deleted file mode 100644 index 07b5e7da98..0000000000 --- a/osu.Game/Performance/HighPerformanceSession.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Allocation; -using osu.Framework.Bindables; -using osu.Framework.Graphics; -using osu.Game.Screens.Play; - -namespace osu.Game.Performance -{ - public partial class HighPerformanceSession : Component - { - private readonly IBindable localUserPlaying = new Bindable(); - - [BackgroundDependencyLoader] - private void load(ILocalUserPlayInfo localUserInfo) - { - localUserPlaying.BindTo(localUserInfo.IsPlaying); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - localUserPlaying.BindValueChanged(playing => - { - if (playing.NewValue) - EnableHighPerformanceSession(); - else - DisableHighPerformanceSession(); - }, true); - } - - protected virtual void EnableHighPerformanceSession() - { - } - - protected virtual void DisableHighPerformanceSession() - { - } - } -} diff --git a/osu.Game/Performance/HighPerformanceSessionManager.cs b/osu.Game/Performance/HighPerformanceSessionManager.cs new file mode 100644 index 0000000000..8a49ba0dac --- /dev/null +++ b/osu.Game/Performance/HighPerformanceSessionManager.cs @@ -0,0 +1,34 @@ +// Copyright (c) ppy Pty Ltd . 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; +using osu.Framework.Graphics; + +namespace osu.Game.Performance +{ + public partial class HighPerformanceSessionManager : Component + { + private GCLatencyMode originalGCMode; + + public IDisposable BeginSession() + { + EnableHighPerformanceSession(); + return new InvokeOnDisposal(this, static m => m.DisableHighPerformanceSession()); + } + + protected virtual void EnableHighPerformanceSession() + { + originalGCMode = GCSettings.LatencyMode; + GCSettings.LatencyMode = GCLatencyMode.LowLatency; + GC.Collect(0); + } + + protected virtual void DisableHighPerformanceSession() + { + if (GCSettings.LatencyMode == GCLatencyMode.LowLatency) + GCSettings.LatencyMode = originalGCMode; + } + } +}