Skip to content

Commit 79467fb

Browse files
committed
Moved performance graph data processing to web worker
Affects issues: - Possibly fixed #4490
1 parent 3db18fd commit 79467fb

2 files changed

Lines changed: 43 additions & 38 deletions

File tree

Plan/react/dashboard/src/util/graphs.js

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,18 @@ export const hasValuesInSeries = series => {
4040
};
4141

4242
export const mapPerformanceDataToSeries = performanceData => {
43-
const playersOnline = [];
44-
const tps = [];
45-
const cpu = [];
46-
const ram = [];
47-
const entities = [];
48-
const chunks = [];
49-
const disk = [];
50-
const msptAverage = [];
51-
const mspt95thPercentile = [];
52-
53-
return new Promise((resolve => {
54-
let i = 0;
55-
const length = performanceData.length;
56-
57-
function processNextThousand() {
58-
const to = Math.min(i + 1000, length);
59-
for (i; i < to; i++) {
60-
const entry = performanceData[i];
61-
const date = entry[0];
62-
playersOnline[i] = [date, entry[1]];
63-
tps[i] = [date, entry[2]];
64-
cpu[i] = [date, entry[3]];
65-
ram[i] = [date, entry[4]];
66-
entities[i] = [date, entry[5]];
67-
chunks[i] = [date, entry[6]];
68-
disk[i] = [date, entry[7]];
69-
msptAverage[i] = [date, entry[8]];
70-
mspt95thPercentile[i] = [date, entry[9]];
71-
}
72-
if (i >= length) {
73-
resolve({playersOnline, tps, cpu, ram, entities, chunks, disk, msptAverage, mspt95thPercentile});
74-
} else {
75-
setTimeout(processNextThousand, 10);
76-
}
77-
}
78-
79-
processNextThousand();
80-
}))
43+
const worker = new Worker(new URL('./workers/performanceGraphWorker.js', import.meta.url));
44+
return new Promise((resolve, error) => {
45+
worker.onmessage = e => {
46+
resolve(e.data)
47+
worker.terminate();
48+
};
49+
worker.onerror = e => {
50+
error(new Error(e.message));
51+
worker.terminate();
52+
};
53+
worker.postMessage(performanceData);
54+
});
8155
};
8256

8357
export const yAxisConfigurations = {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
self.onmessage = (e) => {
2+
const performanceData = e.data;
3+
const playersOnline = [];
4+
const tps = [];
5+
const cpu = [];
6+
const ram = [];
7+
const entities = [];
8+
const chunks = [];
9+
const disk = [];
10+
const msptAverage = [];
11+
const mspt95thPercentile = [];
12+
13+
let i = 0;
14+
const length = performanceData.length;
15+
16+
for (i; i < length; i++) {
17+
const entry = performanceData[i];
18+
const date = entry[0];
19+
playersOnline[i] = [date, entry[1]];
20+
tps[i] = [date, entry[2]];
21+
cpu[i] = [date, entry[3]];
22+
ram[i] = [date, entry[4]];
23+
entities[i] = [date, entry[5]];
24+
chunks[i] = [date, entry[6]];
25+
disk[i] = [date, entry[7]];
26+
msptAverage[i] = [date, entry[8]];
27+
mspt95thPercentile[i] = [date, entry[9]];
28+
}
29+
const processedData = {playersOnline, tps, cpu, ram, entities, chunks, disk, msptAverage, mspt95thPercentile};
30+
self.postMessage(processedData);
31+
};

0 commit comments

Comments
 (0)