From f9bed947b6470d1570cb2a7cca9bb58a8e7a5ccb Mon Sep 17 00:00:00 2001 From: Ulugbek Abdullaev Date: Tue, 28 Oct 2025 17:11:11 +0100 Subject: [PATCH] swb: batch UI updates from running --- .../workbench/stores/simulationRunner.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/simulation/workbench/stores/simulationRunner.ts b/test/simulation/workbench/stores/simulationRunner.ts index 971fdcf741..9121388fc3 100644 --- a/test/simulation/workbench/stores/simulationRunner.ts +++ b/test/simulation/workbench/stores/simulationRunner.ts @@ -411,14 +411,21 @@ class SimulationExecutor { private async interpretOutput(stream: AsyncIterableObject, stdoutFile: string): Promise { const writtenFilesBaseDir = path.dirname(stdoutFile); const entries: RunOutput[] = []; + + const batchProcessor = new BatchProcess( + (batch) => mobx.runInAction(() => batch.forEach((entry) => this.interpretOutputEntry(writtenFilesBaseDir, entry))), + 20 + ); + try { for await (const entry of stream) { entries.push(entry); - mobx.runInAction(() => this.interpretOutputEntry(writtenFilesBaseDir, entry)); // TODO@ulugbekna: we should batch updates + batchProcessor.pushForProcessing(entry); } } catch (e) { console.error('interpretOutput', JSON.stringify(e, null, '\t')); } finally { + batchProcessor.drain(); await fs.promises.writeFile(stdoutFile, JSON.stringify(entries, null, '\t')); this.currentCancellationTokenSource = undefined; mobx.runInAction(() => { @@ -475,3 +482,26 @@ function findInitialTestSummary(runOutput: RunOutput[]): IInitialTestSummaryOutp } return undefined; } + +class BatchProcess { + private readonly batch: T[]; + + constructor( + private readonly processBatch: (batch: T[]) => void, + private readonly batchSize: number + ) { + this.batch = []; + } + + public pushForProcessing(entry: T) { + this.batch.push(entry); + if (this.batch.length >= this.batchSize) { + this.drain(); + } + } + + public drain() { + this.processBatch(this.batch); + this.batch.length = 0; + } +}