-
Notifications
You must be signed in to change notification settings - Fork 1.4k
swb: batch UI updates from running #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -411,14 +411,21 @@ class SimulationExecutor { | |||||||||
| private async interpretOutput(stream: AsyncIterableObject<RunOutput>, stdoutFile: string): Promise<void> { | ||||||||||
| const writtenFilesBaseDir = path.dirname(stdoutFile); | ||||||||||
| const entries: RunOutput[] = []; | ||||||||||
|
|
||||||||||
| const batchProcessor = new BatchProcess<RunOutput>( | ||||||||||
| (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<T> { | ||||||||||
| 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; | ||||||||||
|
Comment on lines
+504
to
+505
|
||||||||||
| this.processBatch(this.batch); | |
| this.batch.length = 0; | |
| const toProcess = this.batch.splice(0); | |
| this.processBatch(toProcess); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
drain()method processes the batch even when it's empty. This creates unnecessary MobX actions and function calls. Add a guard to return early if the batch is empty:if (this.batch.length === 0) { return; }