How to Profile a Slow Build in GitHub Actions
Most bundlers can emit a timing or dependency profile; capturing it in CI shows which modules and plugins dominate the build.
Enable a profiling flag (esbuild --metafile, webpack --profile --json, or vite build --profile), write the report, and upload it so you can open it in an analyzer.
Steps
- Run the build with the bundler profiling flag enabled.
- Write the profile to a file (metafile or stats JSON).
- Upload it as an artifact to inspect locally.
Workflow
.github/workflows/ci.yml
jobs:
build-profile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx esbuild src/index.js --bundle --metafile=meta.json --outfile=out.js
- uses: actions/upload-artifact@v4
with:
name: build-profile
path: meta.jsonGotchas
- Open an esbuild metafile in the official bundle analyzer to see per-module byte and import costs.
- Profiling adds overhead, so read durations as relative, not absolute, build time.
Related guides
How to Enforce a Build-Time Budget in GitHub ActionsFail a GitHub Actions job when the build takes longer than a set number of seconds by timing the build comman…
How to Cache a Browser and Dependencies to Speed Up the Perf Job in GitHub ActionsCut the runtime of a GitHub Actions performance job by caching the dependency store and the headless Chrome t…