Skip to content

cleanup(core): reduce terminal output duplication and allocations in task runner#34427

Merged
FrozenPandaz merged 1 commit intomasterfrom
nxc-3846
Feb 19, 2026
Merged

cleanup(core): reduce terminal output duplication and allocations in task runner#34427
FrozenPandaz merged 1 commit intomasterfrom
nxc-3846

Conversation

@leosvelperez
Copy link
Copy Markdown
Member

Current Behavior

Terminal output in the task runner is accumulated via repeated string concatenation (terminalOutput += chunk). Each += on a growing string causes V8 to allocate a new, larger string and copy the old contents, resulting in O(n²) allocation behavior for tasks with large output. Additionally, PseudoTtyProcess.onExit didn't pass terminalOutput to its callbacks, forcing callers like TaskOrchestrator to duplicate output accumulation logic with a separate onOutput listener.

Expected Behavior

  • Terminal output is collected in string[] arrays and joined once at the end, reducing intermediate allocations from O(n²) to O(n)
  • PseudoTtyProcess.onExit now passes terminalOutput as a second argument, matching the signature of other RunningTask implementations
  • TaskOrchestrator no longer needs a special code path for PseudoTtyProcess — unified onExit handling for all task types
  • tui-summary-life-cycle accumulates output in chunks during execution and stores the finalized string on task completion, allowing chunk arrays to be GC'd
  • SeriallyRunningTasks and RunningNodeProcess similarly switched to chunk-based accumulation
  • BatchProcess and NodeChildProcessWithNonDirectOutput lazily join and cache their terminal output

@leosvelperez leosvelperez self-assigned this Feb 12, 2026
@leosvelperez leosvelperez requested a review from a team as a code owner February 12, 2026 16:03
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Feb 12, 2026

View your CI Pipeline Execution ↗ for commit f52a7d1

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 52m 9s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 43s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-12 17:49:51 UTC

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 12, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f52a7d1
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/698df9bc3ffe57000893db47
😎 Deploy Preview https://deploy-preview-34427--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 12, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f52a7d1
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/698df9bcd29db40007d88eb2
😎 Deploy Preview https://deploy-preview-34427--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

Failed to publish a PR release of this pull request, triggered by @leosvelperez.
See the failed workflow run at: https://github.com/nrwl/nx/actions/runs/21982891900

@github-actions
Copy link
Copy Markdown
Contributor

Failed to publish a PR release of this pull request, triggered by @leosvelperez.
See the failed workflow run at: https://github.com/nrwl/nx/actions/runs/21991021504

@github-actions
Copy link
Copy Markdown
Contributor

Failed to publish a PR release of this pull request, triggered by @leosvelperez.
See the failed workflow run at: https://github.com/nrwl/nx/actions/runs/21994770258

const stoppedTasks = new Set<string>();

// Chunks accumulated progressively during task execution
const taskOutputChunks: Record<string, string[]> = {};
Copy link
Copy Markdown
Contributor

@FrozenPandaz FrozenPandaz Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a duplicate array of the one in the running task...

With the results now having the full terminal output.. can we not store this duplicate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I see that we need the chunks for continuous tasks.

@FrozenPandaz FrozenPandaz merged commit 4f9be49 into master Feb 19, 2026
25 of 26 checks passed
@FrozenPandaz FrozenPandaz deleted the nxc-3846 branch February 19, 2026 00:05
FrozenPandaz pushed a commit that referenced this pull request Feb 20, 2026
… runner (#34427)

## Current Behavior

Terminal output in the task runner is accumulated via repeated string
concatenation (`terminalOutput += chunk`). Each `+=` on a growing string
causes V8 to allocate a new, larger string and copy the old contents,
resulting in O(n²) allocation behavior for tasks with large output.
Additionally, `PseudoTtyProcess.onExit` didn't pass `terminalOutput` to
its callbacks, forcing callers like `TaskOrchestrator` to duplicate
output accumulation logic with a separate `onOutput` listener.

## Expected Behavior

- Terminal output is collected in `string[]` arrays and joined once at
the end, reducing intermediate allocations from O(n²) to O(n)
- `PseudoTtyProcess.onExit` now passes `terminalOutput` as a second
argument, matching the signature of other `RunningTask` implementations
- `TaskOrchestrator` no longer needs a special code path for
`PseudoTtyProcess` — unified `onExit` handling for all task types
- `tui-summary-life-cycle` accumulates output in chunks during execution
and stores the finalized string on task completion, allowing chunk
arrays to be GC'd
- `SeriallyRunningTasks` and `RunningNodeProcess` similarly switched to
chunk-based accumulation
- `BatchProcess` and `NodeChildProcessWithNonDirectOutput` lazily join
and cache their terminal output

(cherry picked from commit 4f9be49)
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants