diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs index e96f239f8..be0f0006c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs @@ -73,8 +73,12 @@ namespace Barotrauma public IPluginManagementService PluginManagementService => _servicesProvider.GetService(); public ILuaScriptManagementService LuaScriptManagementService => _servicesProvider.GetService(); public INetworkingService NetworkingService => _servicesProvider.GetService(); - public IEventService EventService => _servicesProvider.GetService(); - public LuaGame Game => _servicesProvider.GetService(); + // hotpath performance ref cache + private IEventService _eventService = null; + public IEventService EventService => _eventService ??= _servicesProvider.GetService(); + // hotpath performance ref cache + private LuaGame _game; + public LuaGame Game => _game ??= _servicesProvider.GetService(); internal IStorageService StorageService => _servicesProvider.GetService(); @@ -451,6 +455,8 @@ namespace Barotrauma //NetworkingService.Dispose(); EventService.Dispose(); + _eventService = null; + _game = null; _servicesProvider.DisposeAndReset(); } catch (Exception e)