Performance optimizations for large unit counts

This commit is contained in:
Pax1601
2023-07-18 21:56:56 +02:00
parent 785647ad24
commit a4db569fbd
43 changed files with 1188 additions and 580 deletions

View File

@@ -18,7 +18,7 @@ var username = "";
var password = "";
var sessionHash: string | null = null;
var lastUpdateTime = 0;
var lastUpdateTimes: {[key: string]: number} = {}
var demoEnabled = false;
export function toggleDemoEnabled() {
@@ -54,9 +54,14 @@ export function GET(callback: CallableFunction, uri: string, options?: { time?:
/* Success */
setConnected(true);
if (xmlHttp.responseType == 'arraybuffer')
callback(xmlHttp.response);
else
callback(JSON.parse(xmlHttp.responseText));
lastUpdateTimes[uri] = callback(xmlHttp.response);
else {
const result = JSON.parse(xmlHttp.responseText);
lastUpdateTimes[uri] = callback(result);
if ("frameRate" in result && "load" in result)
getConnectionStatusPanel().setMetrics(result.frameRate, result.load);
}
} else if (xmlHttp.status == 401) {
/* Bad credentials */
console.error("Incorrect username/password");
@@ -103,10 +108,6 @@ export function setAddress(address: string, port: number) {
console.log(`Setting REST address to ${REST_ADDRESS}`)
}
export function setLastUpdateTime(newLastUpdateTime: number) {
lastUpdateTime = newLastUpdateTime;
}
export function getAirbases(callback: CallableFunction) {
GET(callback, AIRBASES_URI);
}
@@ -115,8 +116,8 @@ export function getBullseye(callback: CallableFunction) {
GET(callback, BULLSEYE_URI);
}
export function getLogs(callback: CallableFunction) {
GET(callback, LOGS_URI);
export function getLogs(callback: CallableFunction, refresh: boolean = false) {
GET(callback, LOGS_URI, { time: refresh ? 0 : lastUpdateTimes[LOGS_URI]});
}
export function getMission(callback: CallableFunction) {
@@ -124,7 +125,7 @@ export function getMission(callback: CallableFunction) {
}
export function getUnits(callback: CallableFunction, refresh: boolean = false) {
GET(callback, `${UNITS_URI}`, { time: refresh ? 0 : lastUpdateTime }, 'arraybuffer');
GET(callback, UNITS_URI, { time: refresh ? 0 : lastUpdateTimes[UNITS_URI] }, 'arraybuffer');
}
export function addDestination(ID: number, path: any) {
@@ -327,7 +328,7 @@ export function startUpdate() {
getMissionData()?.update(data);
checkSessionHash(data.sessionHash);
});
getUnits((buffer: ArrayBuffer) => getUnitsManager()?.update(buffer), true /* Does a full refresh */);
getUnits((buffer: ArrayBuffer) => {return getUnitsManager()?.update(buffer), true /* Does a full refresh */});
requestUpdate();
requestRefresh();
@@ -336,7 +337,7 @@ export function startUpdate() {
export function requestUpdate() {
/* Main update rate = 250ms is minimum time, equal to server update time. */
if (!getPaused()) {
getUnits((buffer: ArrayBuffer) => { getUnitsManager()?.update(buffer); }, false);
getUnits((buffer: ArrayBuffer) => { return getUnitsManager()?.update(buffer); }, false);
}
window.setTimeout(() => requestUpdate(), getConnected() ? 250 : 1000);
@@ -348,6 +349,13 @@ export function requestRefresh() {
if (!getPaused()) {
getAirbases((data: AirbasesData) => getMissionData()?.update(data));
getBullseye((data: BullseyesData) => getMissionData()?.update(data));
getLogs((data: any) => {
for (let key in data.logs) {
if (key != "requestTime")
console.log(data.logs[key]);
}
return data.time;
});
getMission((data: any) => {
checkSessionHash(data.sessionHash);
getMissionData()?.update(data)