From 66f04f194a686a0340d373f45f8515c18cefa4c5 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 22 Dec 2023 09:27:15 +0000 Subject: [PATCH] Added config to compress profile (zero to none performance difference on high end CPUs) and debug time measurements for load/save times (!178) Co-authored-by: clodan Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/178 Co-authored-by: Alex Co-committed-by: Alex --- project/assets/configs/core.json | 3 ++- project/src/models/spt/config/ICoreConfig.ts | 1 + project/src/servers/SaveServer.ts | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/project/assets/configs/core.json b/project/assets/configs/core.json index 56cffc84..4f4f8bd9 100644 --- a/project/assets/configs/core.json +++ b/project/assets/configs/core.json @@ -11,6 +11,7 @@ "fixProfileBreakingInventoryItemIssues": false }, "features": { - "autoInstallModDependencies": false + "autoInstallModDependencies": false, + "compressProfile": false } } diff --git a/project/src/models/spt/config/ICoreConfig.ts b/project/src/models/spt/config/ICoreConfig.ts index 3d9c6319..13cebaec 100644 --- a/project/src/models/spt/config/ICoreConfig.ts +++ b/project/src/models/spt/config/ICoreConfig.ts @@ -31,4 +31,5 @@ export interface IServerFeatures { /* Controls whether or not the server attempts to download mod dependencies not included in the server's executable */ autoInstallModDependencies: boolean; + compressProfile: boolean; } diff --git a/project/src/servers/SaveServer.ts b/project/src/servers/SaveServer.ts index d5c2beba..527ececf 100644 --- a/project/src/servers/SaveServer.ts +++ b/project/src/servers/SaveServer.ts @@ -7,6 +7,9 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { VFS } from "@spt-aki/utils/VFS"; +import { ConfigServer } from "./ConfigServer"; +import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; +import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig"; @injectable() export class SaveServer @@ -24,6 +27,7 @@ export class SaveServer @inject("HashUtil") protected hashUtil: HashUtil, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("WinstonLogger") protected logger: ILogger, + @inject("ConfigServer") protected configServer: ConfigServer ) {} @@ -166,7 +170,9 @@ export class SaveServer if (this.vfs.exists(filePath)) { // File found, store in profiles[] + const start = performance.now(); this.profiles[sessionID] = this.jsonUtil.deserialize(this.vfs.readFile(filePath), filename); + this.logger.debug(`Profile ${sessionID} took ${performance.now() - start}ms to load.`); } // Run callbacks @@ -200,7 +206,8 @@ export class SaveServer } } - const jsonProfile = this.jsonUtil.serialize(this.profiles[sessionID], true); + const start = performance.now(); + const jsonProfile = this.jsonUtil.serialize(this.profiles[sessionID], !this.configServer.getConfig(ConfigTypes.CORE).features.compressProfile); const fmd5 = this.hashUtil.generateMd5ForData(jsonProfile); if (typeof (this.saveMd5[sessionID]) !== "string" || this.saveMd5[sessionID] !== fmd5) { @@ -209,6 +216,7 @@ export class SaveServer this.vfs.writeFile(filePath, jsonProfile); this.logger.debug(this.localisationService.getText("profile_saved", sessionID), true); } + this.logger.debug(`Profile ${sessionID} took ${performance.now() - start}ms to save.`); } /**