Skip to content
Back to skills

Profiling

ASecurity

How to profile CPU, heap, and bundle size in this repo with Bun's markdown-format profilers. Use when a route or script is slow, memory grows without an obvious owner, the client bundle got bigger, or a performance claim needs a measurement before a rewrite.

  • 3 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 3, 2026
developmentgobashdatabaseperformance

Works with

  • cli

Security analysis

A100/100

Scanned November 30, 2026

npx -y skills add alexpricedev/Billet --skill profiling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Profiling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Profiling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/alexpricedev-profiling/badge)](https://www.skillsdirectory.com/skills/alexpricedev-profiling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: profiling
description: How to profile CPU, heap, and bundle size in this repo with Bun's markdown-format profilers. Use when a route or script is slow, memory grows without an obvious owner, the client bundle got bigger, or a performance claim needs a measurement before a rewrite.
---

# Profiling

Bun 1.4 can emit profiles as Markdown instead of the binary formats that need
Chrome DevTools — which means you can read them directly. Always measure before
rewriting for performance; this repo has already banked one decision that way
(sync compression stays: 18–95µs per response at realistic page sizes, three
orders of magnitude below a database query).

## CPU: where the time goes

```bash
bun --cpu-prof-md ./script-under-test.ts
```

Writes `<name>.cpuprofile.md` in the working directory on exit: a table of
functions by self-time and total-time, with file:line. To profile the server,
run it under the flag, drive load at it (`curl` in a loop, or the benchmark
harness), then SIGTERM it — the profile is written on exit, and the graceful
shutdown handler exits cleanly.

Sampling default is 1000µs; `--cpu-prof-interval=100` for short-lived scripts
that would otherwise land too few samples to mean anything.

## Heap: what's holding memory

```bash
bun --heap-prof-md ./script-under-test.ts
```

Writes a Markdown heap profile on exit — allocation sites by retained size.
Same drive-then-exit pattern for the server. Default sampling is one in 512KB
of allocations; lower `--heap-prof-interval` for finer attribution at the cost
of overhead.

## Bundle: what's in the client JS

```bash
bun build ./src/client/main.ts ./src/client/captcha.ts \
  --outdir /tmp/bundle-analysis --minify \
  --metafile-md=/tmp/bundle-analysis/meta.md
```

The module graph and per-module byte counts, as Markdown. Mirror the exact
flags `scripts/build-assets.ts` uses (`--minify`), add any other entry points in `BUNDLES`
(`src/server/services/bundles.ts`), and build to a scratch dir — never to `dist/assets`, which the dev server serves.

## Ground rules

- Profiles and benchmark numbers are only comparable when recorded back to back
  on the same host. `scripts/benchmark.ts` warns on a recording gap or a
  hardware mismatch for a reason: a container rehosted onto a different CPU
  between recordings once produced a phantom 34% regression.
- Microsecond-scale wins next to a millisecond database query are not wins.
  State the denominator when reporting a finding.
- Don't commit profile output; it belongs in the PR description or a scratch
  file, not the tree.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.