Skip to content

.tip

· one of the small things

node --cpu-prof tells you which function is slow

When a script takes 40 seconds and you can't say which part, the V8 profiler is already in the runtime.

node --cpu-prof --cpu-prof-dir=./prof scripts/import.mjs

It samples the stack while the script runs and writes a .cpuprofile on exit. Drop that file on Chrome DevTools and the Performance panel sorts the heaviest frames to the top of the bottom-up view. No package to install and no code to change, so you profile the script exactly as it is on main. When the problem is memory instead, --heap-prof does the same for allocations.

nodejsperformancedebugging