fix(core): reduce daemon idle cpu usage - #36500
Conversation
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
c3b878f to
832f8f6
Compare
|
@copilot please fix the merge conflicts in this pull request. |
|
View your CI Pipeline Execution ↗ for commit e80207f
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Nx Cloud has identified a possible root cause for your failed CI:
We reviewed the three failing tasks and confirmed they are pre-existing failures also present on master, unrelated to this PR's change. The e2e-web failures stem from a webpack@5.110.0 internal incompatibility, and the e2e-remix timeout is a pre-existing CI environment slowness — neither has any connection to the daemon setInterval adjustment from 20ms to 500ms.
No code changes were suggested for this issue.
You can trigger a rerun by pushing an empty commit:
git commit --allow-empty -m "chore: trigger rerun"
git push
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
🎓 Learn more about Self-Healing CI on nx.dev
e80207f to
e1ea1c5
Compare
startServer() runs setInterval(..., 20) for the entire daemon lifetime, ticking 50x/sec even when the workspace is completely idle. PR nrwl#32618 fixed the missing delay (it used to fire as fast as the event loop allowed) but the tick rate itself is still way higher than needed. Bumped the interval from 20ms to 500ms. Tested locally on a fresh angular-standalone workspace, idle daemon CPU dropped from 6-10% to ~1%. No correctness issues observed in manual testing. Closes nrwl#36467
e1ea1c5 to
1830df8
Compare
…LLING_INTERVAL Falls back to 500ms if the env var is unset or non-numeric.
224c001 to
29244cc
Compare
|
Added |
Current Behavior
Nx daemon uses 6-10% CPU even when the workspace is completely idle
(no file changes, no tasks running, no editor open).
Root cause is in
startServer()(packages/nx/src/daemon/server/server.ts):setInterval(..., 20)runs for the whole daemon lifetime, i.e. 50 ticks/secregardless of whether anything is happening.
#32618 already fixed the interval's missing delay (previously fired as
fast as the event loop allowed), but the 20ms tick rate itself is still
unnecessarily aggressive.
What changed
Bumped the interval to 500ms.
Testing
Tested locally on a fresh workspace (
npx create-nx-workspace@latest --preset=angular-standalone):Went with 500ms as a reasonable middle ground — didn't notice any
change in daemon responsiveness or correctness across normal usage
(builds, cache hits, file watching).
Happy to adjust the value or make it configurable if that's preferred.
Closes #36467