Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose no-op constructors as protected #30335

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

peppy
Copy link
Member

@peppy peppy commented Oct 18, 2024

This allows bypassing the population of Guid based IDs, which can have considerable overhead in batch usage cases, where we are 100% sure we aren't ever storing to realm:

image
image

Consumption looks like this:

diff --git a/osu.Server.Queues.ScoreStatisticsProcessor/Models/SoloScore.cs b/osu.Server.Queues.ScoreStatisticsProcessor/Models/SoloScore.cs
index a649708..260ad39 100644
--- a/osu.Server.Queues.ScoreStatisticsProcessor/Models/SoloScore.cs
+++ b/osu.Server.Queues.ScoreStatisticsProcessor/Models/SoloScore.cs
@@ -84,19 +84,20 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Models
         public ScoreInfo ToScoreInfo()
         {
             var ruleset = LegacyRulesetHelper.GetRulesetFromLegacyId(ruleset_id);
+            var beatmapInfo = new LightweightBeatmapInfo
+            {
+                OnlineID = (int)beatmap_id,
+                Ruleset = new RulesetInfo { OnlineID = beatmap!.playmode }
+            };
 
-            return new ScoreInfo
+            return new LightweightScoreInfo
             {
                 OnlineID = (long)id,
                 LegacyOnlineID = (long?)legacy_score_id ?? -1,
                 IsLegacyScore = is_legacy_score,
                 User = new APIUser { Id = (int)user_id },
-                BeatmapInfo = new BeatmapInfo
-                {
-                    OnlineID = (int)beatmap_id,
-                    Ruleset = new RulesetInfo { OnlineID = beatmap!.playmode }
-                },
                 Ruleset = new RulesetInfo { OnlineID = ruleset_id },
+                BeatmapInfo = beatmapInfo,
                 Passed = passed,
                 TotalScore = total_score,
                 LegacyTotalScore = legacy_total_score,
@@ -112,5 +113,13 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Models
                 Ranked = ranked,
             };
         }
+
+        private class LightweightBeatmapInfo : BeatmapInfo
+        {
+        }
+
+        private class LightweightScoreInfo : ScoreInfo
+        {
+        }
     }
 }

@bdach
Copy link
Collaborator

bdach commented Oct 18, 2024

These sorts of changes always make me a bit nervous, but upon looking at things I believe it should be fine, because:

  • When realm is actually present (i.e. client-side), deriving from both of these classes is not allowed and fody will loudly protest about it.
  • The ctor is still protected, which means there should be no surprises like some usage suddenly switching from the ctor with multiple params with defaults to the true parameterless one.

And looking at IL with the patch applied it does look like this would skip the guid initialisation.

@bdach bdach merged commit 7ba17b9 into ppy:master Oct 18, 2024
11 of 13 checks passed
@peppy peppy deleted the expose-noop-ctors branch October 22, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants