Converted collections to their frozen counterparts for improved lookup speed

This commit is contained in:
Chomp
2025-07-14 19:56:20 +01:00
parent 3aa13dd46b
commit 5ef2271a29
17 changed files with 58 additions and 44 deletions
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Generators;
@@ -45,7 +46,7 @@ public class HideoutController(
{
public const string NameTaskConditionCountersCraftingId = "673f5d6fdd6ed700c703afdc";
protected readonly HashSet<HideoutAreas> _areasWithResources =
protected readonly FrozenSet<HideoutAreas> _areasWithResources =
[
HideoutAreas.AirFilteringUnit,
HideoutAreas.WaterCollector,
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Generators.RepeatableQuestGeneration;
@@ -45,7 +46,12 @@ public class RepeatableQuestController(
ICloner cloner
)
{
protected static readonly List<string> _questTypes = ["PickUp", "Exploration", "Elimination"];
protected static readonly FrozenSet<string> _questTypes =
[
"PickUp",
"Exploration",
"Elimination",
];
protected readonly QuestConfig QuestConfig = configServer.GetConfig<QuestConfig>();
/// <summary>
@@ -19,7 +19,7 @@ namespace SPTarkov.Server.Core.Extensions
public static bool IsSameItem(
this Item item1,
Item item2,
HashSet<string>? compareUpdProperties = null
ISet<string>? compareUpdProperties = null
)
{
// Different tpl == different item
@@ -51,10 +51,10 @@ public class BotInventoryGenerator(
private readonly BotConfig _botConfig = configServer.GetConfig<BotConfig>();
private readonly HashSet<string> _slotsToCheck =
private readonly FrozenSet<string> _slotsToCheck =
[
EquipmentSlots.Pockets.ToString(),
EquipmentSlots.SecuredContainer.ToString(),
nameof(EquipmentSlots.Pockets),
nameof(EquipmentSlots.SecuredContainer),
];
/// <summary>
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
@@ -23,7 +24,7 @@ public class RagfairAssortGenerator(
{
protected readonly RagfairConfig RagfairConfig = configServer.GetConfig<RagfairConfig>();
protected readonly List<MongoId> RagfairItemInvalidBaseTypes =
protected readonly FrozenSet<MongoId> RagfairItemInvalidBaseTypes =
[
BaseClasses.LOOT_CONTAINER, // Safe, barrel cache etc
BaseClasses.STASH, // Player inventory stash
@@ -58,7 +59,7 @@ public class RagfairAssortGenerator(
.Where(item => !string.Equals(item.Type, "Node", StringComparison.OrdinalIgnoreCase));
// Store processed preset tpls so we don't add them when processing non-preset items
HashSet<string> processedArmorItems = [];
HashSet<MongoId> processedArmorItems = [];
var seasonalEventActive = seasonalEventService.SeasonalEventEnabled();
var seasonalItemTplBlacklist = seasonalEventService.GetInactiveSeasonalEventItems();
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
@@ -34,13 +35,14 @@ public class EliminationQuestGenerator(
/// <summary>
/// Body parts to present to the client as opposed to the body part information in quest data.
/// </summary>
private static readonly Dictionary<string, List<string>> _bodyPartsToClient = new()
{
{ BodyParts.Arms, [BodyParts.LeftArm, BodyParts.RightArm] },
{ BodyParts.Legs, [BodyParts.LeftLeg, BodyParts.RightLeg] },
{ BodyParts.Head, [BodyParts.Head] },
{ BodyParts.Chest, [BodyParts.Chest, BodyParts.Stomach] },
};
private static readonly FrozenDictionary<string, List<string>> _bodyPartsToClient =
new Dictionary<string, List<string>>
{
{ BodyParts.Arms, [BodyParts.LeftArm, BodyParts.RightArm] },
{ BodyParts.Legs, [BodyParts.LeftLeg, BodyParts.RightLeg] },
{ BodyParts.Head, [BodyParts.Head] },
{ BodyParts.Chest, [BodyParts.Chest, BodyParts.Stomach] },
}.ToFrozenDictionary();
/// <summary>
/// MaxDistDifficulty is defined by 2, this could be a tuning parameter if we don't like the reward generation
@@ -1,4 +1,5 @@
using System.Net;
using System.Collections.Frozen;
using System.Net;
using System.Net.Sockets;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Spt.Config;
@@ -11,7 +12,7 @@ public class HttpServerHelper(ConfigServer configServer)
{
protected readonly HttpConfig _httpConfig = configServer.GetConfig<HttpConfig>();
protected readonly Dictionary<string, string> mime = new()
protected readonly FrozenDictionary<string, string> mime = new Dictionary<string, string>
{
{ "css", "text/css" },
{ "bin", "application/octet-stream" },
@@ -22,7 +23,7 @@ public class HttpServerHelper(ConfigServer configServer)
{ "png", "image/png" },
{ "svg", "image/svg+xml" },
{ "txt", "text/plain" },
};
}.ToFrozenDictionary();
public string? GetMimeText(string key)
{
@@ -1,4 +1,5 @@
using SPTarkov.Common.Extensions;
using System.Collections.Frozen;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Models.Common;
@@ -19,7 +20,7 @@ public class InRaidHelper(
DatabaseService databaseService
)
{
protected static readonly List<string> _pocketSlots =
protected static readonly FrozenSet<string> _pocketSlots =
[
"pocket1",
"pocket2",
@@ -157,7 +157,7 @@ public class ItemHelper(
public bool IsSameItems(
ICollection<Item> item1,
ICollection<Item> item2,
HashSet<string>? compareUpdProperties = null
ISet<string>? compareUpdProperties = null
)
{
if (item1.Count != item2.Count)
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using System.Globalization;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
@@ -38,7 +39,7 @@ public class QuestHelper(
ICloner cloner
)
{
protected readonly HashSet<QuestStatusEnum> _startedOrAvailToFinish =
protected readonly FrozenSet<QuestStatusEnum> _startedOrAvailToFinish =
[
QuestStatusEnum.Started,
QuestStatusEnum.AvailableForFinish,
@@ -28,7 +28,7 @@ public class BtrDeliveryService(
configServer.GetConfig<BtrDeliveryConfig>();
protected readonly TraderConfig _traderConfig = configServer.GetConfig<TraderConfig>();
protected static readonly List<string> _transferTypes = new() { "btr", "transit" };
protected static readonly List<string> _transferTypes = ["btr", "transit"];
/// <summary>
/// Check if player used BTR or transit item sending service and send items to player via mail if found
@@ -42,7 +42,7 @@ public class BtrDeliveryService(
var rootId = $"{Traders.BTR}_{transferType}";
List<Item>? itemsToSend = null;
// if rootId doesnt exist in TransferItems, skip
// if rootId doesn't exist in TransferItems, skip
if (!request?.TransferItems?.TryGetValue(rootId, out itemsToSend) ?? false)
{
continue;
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
@@ -44,7 +45,7 @@ public class FenceService(
/// </summary>
protected TraderAssort? fenceDiscountAssort;
protected readonly HashSet<string> fenceItemUpdCompareProperties =
protected readonly FrozenSet<string> fenceItemUpdCompareProperties =
[
"Buff",
"Repairable",
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
@@ -29,12 +30,12 @@ public class MailSendService(
)
{
private const string _systemSenderId = "59e7125688a45068a6249071";
protected readonly HashSet<MessageType> _messageTypes =
protected readonly FrozenSet<MessageType> _messageTypes =
[
MessageType.NpcTraderMessage,
MessageType.FleamarketMessage,
];
protected readonly HashSet<string> _slotNames = ["hideout", "main"];
protected readonly FrozenSet<string> _slotNames = ["hideout", "main"];
/// <summary>
/// Send a message from an NPC (e.g. prapor) to the player with or without items using direct message text, do not look up any locale
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Constants;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
@@ -14,7 +15,7 @@ namespace SPTarkov.Server.Core.Services;
[Injectable(InjectionType.Singleton)]
public class MatchBotDetailsCacheService(ISptLogger<MatchBotDetailsCacheService> logger)
{
private static readonly HashSet<string> _sidesToCache = [Sides.PmcUsec, Sides.PmcBear];
private static readonly FrozenSet<string> _sidesToCache = [Sides.PmcUsec, Sides.PmcBear];
protected readonly ConcurrentDictionary<string, BotDetailsForChatMessages> BotDetailsCache =
new();
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using System.Text.RegularExpressions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
@@ -29,7 +30,7 @@ public class ProfileFixerService(
InventoryHelper inventoryHelper
)
{
protected readonly List<string> _areas = ["hideout", "main"];
protected readonly FrozenSet<string> _areas = ["hideout", "main"];
protected readonly CoreConfig _coreConfig = configServer.GetConfig<CoreConfig>();
/// <summary>
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
@@ -28,7 +29,7 @@ public class SeasonalEventService(
{
private bool _christmasEventActive;
protected readonly HashSet<MongoId> _christmasEventItems =
protected readonly FrozenSet<MongoId> _christmasEventItems =
[
ItemTpl.ARMOR_6B13_M_ASSAULT_ARMOR_CHRISTMAS_EDITION,
ItemTpl.BACKPACK_SANTAS_BAG,
@@ -61,7 +62,7 @@ public class SeasonalEventService(
private List<SeasonalEvent> _currentlyActiveEvents = [];
protected readonly HashSet<EquipmentSlots> _equipmentSlotsToFilter =
protected readonly FrozenSet<EquipmentSlots> _equipmentSlotsToFilter =
[
EquipmentSlots.FaceCover,
EquipmentSlots.Headwear,
@@ -71,7 +72,7 @@ public class SeasonalEventService(
private bool _halloweenEventActive;
protected readonly HashSet<MongoId> _halloweenEventItems =
protected readonly FrozenSet<MongoId> _halloweenEventItems =
[
ItemTpl.HEADWEAR_JACKOLANTERN_TACTICAL_PUMPKIN_HELMET,
ItemTpl.FACECOVER_FACELESS_MASK,
@@ -88,12 +89,6 @@ public class SeasonalEventService(
protected readonly HttpConfig _httpConfig = configServer.GetConfig<HttpConfig>();
protected readonly LocationConfig _locationConfig = configServer.GetConfig<LocationConfig>();
protected readonly HashSet<string> _lootContainersToFilter =
[
"Backpack",
"Pockets",
"TacticalVest",
];
protected readonly QuestConfig _questConfig = configServer.GetConfig<QuestConfig>();
protected readonly SeasonalEventConfig _seasonalEventConfig =
configServer.GetConfig<SeasonalEventConfig>();
@@ -103,7 +98,7 @@ public class SeasonalEventService(
/// Get an array of christmas items found in bots inventories as loot
/// </summary>
/// <returns>array</returns>
public HashSet<MongoId> GetChristmasEventItems()
public FrozenSet<MongoId> GetChristmasEventItems()
{
return _christmasEventItems;
}
@@ -112,7 +107,7 @@ public class SeasonalEventService(
/// Get an array of halloween items found in bots inventories as loot
/// </summary>
/// <returns>array</returns>
public HashSet<MongoId> GetHalloweenEventItems()
public FrozenSet<MongoId> GetHalloweenEventItems()
{
return _halloweenEventItems;
}
@@ -207,7 +202,7 @@ public class SeasonalEventService(
/// <summary>
/// Get a dictionary of gear changes to apply to bots for a specific event e.g. Christmas/Halloween
/// </summary>
/// <param name="eventName">Name of event to get gear changes for</param>
/// <param name="eventType">Name of event to get gear changes for</param>
/// <returns>bots with equipment changes</returns>
protected Dictionary<string, Dictionary<string, Dictionary<MongoId, int>>>? GetEventBotGear(
SeasonalEventType eventType
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Utils;
@@ -20,8 +21,9 @@ public class ServerLocalisationService(
{
private readonly Dictionary<string, LazyLoad<Dictionary<string, string>>> _loadedLocales = [];
private string _serverLocale = localeService.GetDesiredServerLocale();
private readonly Dictionary<string, string> _localeFallbacks =
localeService.GetLocaleFallbacks();
private readonly FrozenDictionary<string, string> _localeFallbacks = localeService
.GetLocaleFallbacks()
.ToFrozenDictionary();
private const string DefaultLocale = "en";
private const string LocaleDirectory = "./SPT_Data/database/locales/server";