Skip to content

Commit

Permalink
Use static ruleset classes rather than constructing on each usage
Browse files Browse the repository at this point in the history
These are used a *lot*, so this is quite a large saving. Mainly just
aiming to get GC time down.
  • Loading branch information
peppy committed Oct 18, 2024
1 parent 6641b1f commit 5b56db2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Helpers
{
public static class LegacyDatabaseHelper
{
private static readonly RulesetDatabaseInfo osu_info = new RulesetDatabaseInfo(0, "osu", false);
private static readonly RulesetDatabaseInfo taiko_info = new RulesetDatabaseInfo(1, "taiko", true);
private static readonly RulesetDatabaseInfo fruits_info = new RulesetDatabaseInfo(2, "fruits", true);
private static readonly RulesetDatabaseInfo mania_info = new RulesetDatabaseInfo(3, "mania", true);

public static RulesetDatabaseInfo GetRulesetSpecifics(int rulesetId)
{
switch (rulesetId)
{
default:
case 0:
return new RulesetDatabaseInfo(0, "osu", false);
return osu_info;

case 1:
return new RulesetDatabaseInfo(1, "taiko", true);
return taiko_info;

case 2:
return new RulesetDatabaseInfo(2, "fruits", true);
return fruits_info;

case 3:
return new RulesetDatabaseInfo(3, "mania", true);
return mania_info;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@ namespace osu.Server.Queues.ScoreStatisticsProcessor.Helpers
{
public static class LegacyRulesetHelper
{
private static readonly Ruleset osu_ruleset = new OsuRuleset();
private static readonly Ruleset taiko_ruleset = new TaikoRuleset();
private static readonly Ruleset catch_ruleset = new CatchRuleset();
private static readonly Ruleset mania_ruleset = new ManiaRuleset();

public static Ruleset GetRulesetFromLegacyId(int legacyId)
{
switch (legacyId)
{
case 0:
return new OsuRuleset();
return osu_ruleset;

case 1:
return new TaikoRuleset();
return taiko_ruleset;

case 2:
return new CatchRuleset();
return catch_ruleset;

case 3:
return new ManiaRuleset();
return mania_ruleset;

default:
throw new ArgumentException($"Invalid ruleset ID: {legacyId}", nameof(legacyId));
Expand Down

0 comments on commit 5b56db2

Please sign in to comment.