Skip to content

fix(core): optimize task hashing with BFS and performance logging#32911

Merged
FrozenPandaz merged 1 commit intomasterfrom
perf/optimize-task-hashing
Oct 1, 2025
Merged

fix(core): optimize task hashing with BFS and performance logging#32911
FrozenPandaz merged 1 commit intomasterfrom
perf/optimize-task-hashing

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Contributor

@FrozenPandaz FrozenPandaz commented Oct 1, 2025

Summary

Optimizes get_dep_output by replacing recursive traversal with BFS + parallel processing.

Key optimization: The old recursive implementation processed the same task multiple times when it appeared in multiple dependency paths (diamond dependencies). The new implementation:

  • Uses BFS with a visited HashSet to process each task exactly once
  • Collects all tasks first, then processes them in parallel with Rayon
  • Returns task references directly, eliminating redundant HashMap lookups

This deduplicates work and leverages parallelism, significantly improving performance on large task graphs.

Note: Only processes regular dependencies, not continuous_dependencies, since continuous tasks (like watch/serve) don't produce outputs that need to be hashed.

The same test on my machine without these changes takes many minutes before crashing my editor. Now it takes <3ms.

Test plan

  • ✅ All Rust tests passing
  • ✅ Native module builds successfully
  • ✅ Added 4 unit tests covering direct dependencies, transitive dependencies, diamond deduplication, and task output filtering
  • ✅ Added performance test verifying large graphs (depth 30 = 90 tasks) complete in <10ms

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Oct 1, 2025 3:26pm

@netlify
Copy link
Copy Markdown

netlify Bot commented Oct 1, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 14f87b5
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/68dd430edcbe45000950a682
😎 Deploy Preview https://deploy-preview-32911--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.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Oct 1, 2025

View your CI Pipeline Execution ↗ for commit 14f87b5

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 41m 3s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 1m 55s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 6s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 4m 36s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-01 15:57:22 UTC

nx-cloud[bot]

This comment was marked as outdated.

@FrozenPandaz FrozenPandaz force-pushed the perf/optimize-task-hashing branch 3 times, most recently from 2565314 to cda35df Compare October 1, 2025 01:44
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

Nx Cloud has identified a possible root cause for your failed CI:

The documentation generation task failed because it detected modified files that need to be committed. However, these documentation changes are not caused by the code changes in this pull request.

The PR modifies only Rust files in the task hashing pipeline:

  • packages/nx/src/native/tasks/dep_outputs.rs
  • packages/nx/src/native/tasks/hash_planner.rs
  • packages/nx/src/native/tasks/task_hasher.rs

The failing documentation changes are in TypeScript devkit documentation for PostTasksExecutionContext and PreTasksExecutionContext, removing fields like endTime, id, and startTime. These interface changes are unrelated to Rust task hashing optimizations.

The most likely causes:

  1. The documentation was generated from a TypeScript source that was modified in a previous commit or on the base branch
  2. There are uncommitted changes in the workspace from previous work
  3. The documentation generator is picking up changes from the merged base branch (commit message shows a merge: "Merge 0499f6e into 1bea913")

This is classified as 'environment_state' because the failure is caused by the current state of the repository (uncommitted documentation changes or changes from the base branch merge), not by the actual code changes in this PR which only touch Rust performance optimization code.

No code changes are warranted. The documentation files should be committed separately or the workspace should be cleaned to remove these unrelated changes before re-running the documentation task.

A code change would likely not resolve this issue, so no action was taken.

Nx CloudView in Nx Cloud ↗


⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.

@FrozenPandaz FrozenPandaz force-pushed the perf/optimize-task-hashing branch 2 times, most recently from c8eae46 to 00956ca Compare October 1, 2025 02:34
@FrozenPandaz FrozenPandaz changed the title perf(core): optimize task hashing with BFS and performance logging fix(core): optimize task hashing with BFS and performance logging Oct 1, 2025
@FrozenPandaz FrozenPandaz force-pushed the perf/optimize-task-hashing branch from 00956ca to e4269ca Compare October 1, 2025 13:37
@FrozenPandaz FrozenPandaz marked this pull request as ready for review October 1, 2025 14:50
@FrozenPandaz FrozenPandaz requested review from a team as code owners October 1, 2025 14:50
@FrozenPandaz FrozenPandaz force-pushed the perf/optimize-task-hashing branch from e4269ca to 130afac Compare October 1, 2025 15:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 1, 2025

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx create-nx-workspace@0.0.0-pr-32911-14f87b5 my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-32911-14f87b5
Release details 📑
Published version 0.0.0-pr-32911-14f87b5
Triggered by @FrozenPandaz
Branch perf/optimize-task-hashing
Commit 14f87b5
Workflow run 18166899664

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@FrozenPandaz FrozenPandaz enabled auto-merge (squash) October 1, 2025 17:06
@FrozenPandaz FrozenPandaz merged commit e5ac4a8 into master Oct 1, 2025
19 checks passed
@FrozenPandaz FrozenPandaz deleted the perf/optimize-task-hashing branch October 1, 2025 17:27
FrozenPandaz added a commit that referenced this pull request Oct 1, 2025
…2911)

## Summary

Optimizes `get_dep_output` by replacing recursive traversal with BFS +
parallel processing.

**Key optimization**: The old recursive implementation processed the
same task multiple times when it appeared in multiple dependency paths
(diamond dependencies). The new implementation:
- Uses BFS with a visited HashSet to process each task exactly once
- Collects all tasks first, then processes them in parallel with Rayon
- Returns task references directly, eliminating redundant HashMap
lookups

This deduplicates work and leverages parallelism, significantly
improving performance on large task graphs.

**Note**: Only processes regular dependencies, not
continuous_dependencies, since continuous tasks (like watch/serve) don't
produce outputs that need to be hashed.

The same test on my machine without these changes takes many minutes
before crashing my editor. Now it takes <3ms.

## Test plan

- ✅ All Rust tests passing
- ✅ Native module builds successfully
- ✅ Added 4 unit tests covering direct dependencies, transitive
dependencies, diamond deduplication, and task output filtering
- ✅ Added performance test verifying large graphs (depth 30 = 90 tasks)
complete in <10ms

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

github-actions Bot commented Oct 7, 2025

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 Oct 7, 2025
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