From 5df46d0a54785719585b47646dfc305674615e9e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 20 Jan 2022 20:23:17 +0900 Subject: [PATCH] Remove all calls to `Realm.Refresh` to fix blocking overhead from subscriptions Turns out this is not required if realm is aware of a `SynchronizationContext`. See https://github.com/realm/realm-dotnet/discussions/2775#discussioncomment-2005412 for further reading. --- osu.Game/Database/EFToRealmMigrator.cs | 3 --- osu.Game/Database/RealmContextFactory.cs | 14 +------------- osu.Game/OsuGameBase.cs | 7 ------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/osu.Game/Database/EFToRealmMigrator.cs b/osu.Game/Database/EFToRealmMigrator.cs index cff83938bf..0f726f8ee5 100644 --- a/osu.Game/Database/EFToRealmMigrator.cs +++ b/osu.Game/Database/EFToRealmMigrator.cs @@ -46,9 +46,6 @@ namespace osu.Game.Database migrateScores(ef); } - Logger.Log("Refreshing realm...", LoggingTarget.Database); - realmContextFactory.Refresh(); - // Delete the database permanently. // Will cause future startups to not attempt migration. Logger.Log("Migration successful, deleting EF database", LoggingTarget.Database); diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index 99b357710e..31dbb0c6c4 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -61,10 +61,10 @@ namespace osu.Game.Database private readonly ThreadLocal currentThreadCanCreateContexts = new ThreadLocal(); - private static readonly GlobalStatistic refreshes = GlobalStatistics.Get(@"Realm", @"Dirty Refreshes"); private static readonly GlobalStatistic contexts_created = GlobalStatistics.Get(@"Realm", @"Contexts (Created)"); private readonly object contextLock = new object(); + private Realm? context; public Realm Context @@ -169,18 +169,6 @@ namespace osu.Game.Database /// public bool Compact() => Realm.Compact(getConfiguration()); - /// - /// Perform a blocking refresh on the main realm context. - /// - public void Refresh() - { - lock (contextLock) - { - if (context?.Refresh() == true) - refreshes.Value++; - } - } - public Realm CreateContext() { if (isDisposed) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index fb09dac1b1..5af992f800 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -351,13 +351,6 @@ namespace osu.Game FrameStatistics.ValueChanged += e => fpsDisplayVisible.Value = e.NewValue != FrameStatisticsMode.None; } - protected override void Update() - { - base.Update(); - - realmFactory.Refresh(); - } - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent));