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 <clodan@clodan.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/178
Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com>
Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
This commit is contained in:
Alex 2023-12-22 09:27:15 +00:00 committed by chomp
parent c7572fdaf2
commit 66f04f194a
3 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,7 @@
"fixProfileBreakingInventoryItemIssues": false
},
"features": {
"autoInstallModDependencies": false
"autoInstallModDependencies": false,
"compressProfile": false
}
}

View File

@ -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;
}

View File

@ -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<ICoreConfig>(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.`);
}
/**