# Memory benchmarks

These measurements describe one machine and one Pi version. They are evidence for this implementation, not a claim about every runtime or operating system.

## Environment

- Pi 0.82.1
- Bun 1.4.0-canary.1
- macOS on Apple Silicon
- extension loaded as an explicit Pi extension
- no skills, themes, prompt templates, context files, or other extensions
- offline model startup

## Startup peak

Nine alternating runs used macOS `/usr/bin/time -l` with `pi --list-models`.

| Variant                                    | Median peak RSS |
| ------------------------------------------ | --------------: |
| Pi without the extension                   |       174.2 MiB |
| Pi with the optimized TypeScript extension |       173.3 MiB |

The difference is smaller than normal run-to-run variance. It should be read as "no measurable idle increase in this benchmark," not as negative memory use.

A precompiled JavaScript copy measured 176.1 MiB and did not improve startup memory. Pi's TypeScript loader was therefore retained.

## After one request

A deterministic local Responses endpoint was used to isolate runtime allocation from network latency.

| Variant                           | RSS over baseline | Physical footprint over baseline |
| --------------------------------- | ----------------: | -------------------------------: |
| Direct `fetch()` in the extension |          +4.4 MiB |                         +4.0 MiB |
| Short-lived external curl process |          +3.0 MiB |                         +3.0 MiB |

The process helper saved about 1 MiB of physical memory after a search but added a subprocess, executable dependency, and more failure modes. The extension keeps the direct `fetch()` implementation.

## Reproduction notes

The useful controls are:

- alternate variant order to reduce drift
- report medians across multiple runs
- separate startup peak from a long-lived idle process
- use `footprint` in addition to RSS on macOS
- compare identical response payloads when measuring the first search call

Do not interpret one process snapshot as a stable memory result. Bun may retain reusable heap pages even after JavaScript objects become unreachable.
