Skip to content

Commit

Permalink
Fix issue with parser
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Nov 16, 2023
1 parent df28384 commit 76a062f
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions client/src/components/renderer/parser/parseTrace.worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chunk, flatMap, map, range } from "lodash";
import { ceil, flatMap, flatten, map, range } from "lodash";
import { usingWorkerTask } from "../../../workers/usingWorker";
import {
ParseTraceWorkerParameters,
Expand All @@ -9,7 +9,6 @@ import parseTraceWorkerUrl from "./parseTraceSlave.worker.ts?worker&url";
const { min } = Math;

const SLAVE_COUNT = navigator.hardwareConcurrency ?? 8;
const CHUNK_SIZE = 16;

export class ParseTraceWorker extends Worker {
constructor() {
Expand All @@ -27,25 +26,21 @@ async function parse({
context,
view = "main",
}: ParseTraceWorkerParameters): Promise<ParseTraceWorkerReturnType> {
const chunks = range(0, trace?.events?.length, CHUNK_SIZE);
const tasks = chunk(chunks, SLAVE_COUNT);
const outs = [];

for (const task of tasks) {
outs.push(
...(await Promise.all(
map(task, (i) =>
parseTraceWorker({
trace,
context,
view,
from: i,
to: min(i + CHUNK_SIZE, trace?.events?.length ?? 0),
})
)
))
);
}
const chunkSize = ceil((trace?.events?.length ?? 0) / SLAVE_COUNT);
const chunks = range(0, trace?.events?.length, chunkSize);
const outs = flatten(
await Promise.all(
map(chunks, (i) =>
parseTraceWorker({
trace,
context,
view,
from: i,
to: min(i + chunkSize, trace?.events?.length ?? 0),
})
)
)
);

return {
stepsPersistent: flatMap(outs, "stepsPersistent"),
Expand Down

0 comments on commit 76a062f

Please sign in to comment.