workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

esbuild using non-negligible CPU time when nothing is happening

Open kentonv opened this issue 1 month ago • 4 comments

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

kentonv avatar Nov 29 '25 14:11 kentonv

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?

petebacondarwin avatar Dec 01 '25 12:12 petebacondarwin

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!

kentonv avatar Dec 01 '25 20:12 kentonv

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?

kentonv avatar Dec 01 '25 20:12 kentonv

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...

petebacondarwin avatar Dec 01 '25 20:12 petebacondarwin