Luke Oliff.

TIL: Profiling Node.js Build Performance With node --prof

·TIL·1 min read·Luke Oliff

A build that takes ten seconds is fine. A build that takes ten minutes is a problem. Node’s built-in profiler tells you where the time goes.

node --prof build-script.js

This generates an isolate-*.log file with V8 tick samples. Process it into readable text.

node --prof-process isolate-*.log > profile.txt

The output shows total ticks per JavaScript function, C++ function, and system call. One look at the profile and you see whether your build is slow because of a specific plugin, a file IO bottleneck, or a third party script.

I used this at Netlify when a plugin build went from 30 seconds to 3 minutes after a version bump. The profile pointed straight at a new dependency doing sync file reads in a loop.

Does profiling affect performance?

Yes, slightly. The profiler samples the stack at regular intervals. The overhead is small enough for build analysis but do not run it in production.

Can I profile an already running process?

Send SIGUSR1 to the process to enable the inspector, then connect with Chrome DevTools.