esbuild using non-negligible CPU time when nothing is happening
What versions & operating system are you using?
System:
OS: Linux 6.14 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (88) x64 Intel(R) Xeon(R) w9-3575X
Memory: 202.60 GB / 250.93 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.13.0 - /home/kenton/.volta/tools/image/node/22.13.0/bin/node
npm: 10.9.2 - /home/kenton/.volta/tools/image/node/22.13.0/bin/npm
pnpm: 10.22.0 - /home/kenton/.volta/bin/pnpm
npmPackages:
wrangler: ^4.50.0 => 4.50.0
Please provide a link to a minimal reproduction
N/A
Describe the Bug
When wrangler dev is running, but no changes are being made, I often catch esbuild using 5%-25% CPU. Why is esbuild even running when there are no changes?
Please provide any relevant error logs
No response
Indeed, esbuild should be doing nothing (except watching files) when no changes have been made. Is it possible that it had to fallback to polling the file system to monitor for changes?
Hmm, so esbuild itself does the file-watching, not wrangler?
According to https://github.com/evanw/esbuild/issues/1204, esbuild's "watch" mode may be based on polling rather than inotify, though the bug is pretty old. If true this is very disappointing!
Looks like the recommendation is to do file watching outside esbuild and then just re-run esbuild whenever needed. There's probably an easy npm library wrangler could use for this?
We do actually have some external file watching in place, e.g. for config file changes, assets files, etc. The pain with externally watching source files is that you have to keep track of which ones have been imported and watch those too.
This is all possible but in generally I haven't seen esbuild churning lots of CPU so it hasn't come up as a thing to fix. But then again we only really use MacOS in the team.
Out of interest, have you played with the vite-plugin much? It has just about the same feature set as wrangler dev these days and might be more efficient in its use of esbuild...