AGENTS.md
src/terminal/compress/AGENTS.mdAGENTS.md
Quality
76/100
Scores the file, not the repository.Length
632 words
7 headings · 0 code blocksRepository
59k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Terminal Compression23Guidance for the codecs and the compressed page representation4(`Page.zig`) in this directory. These compress terminal page backing5memory (`terminal.Page`).67## Priorities89When making tradeoffs, in order:10111. **Compression ratio on page-shaped data.** Encoded bytes are retained12 scrollback memory, and raw `terminal.Page` backing memory is the only13 thing we actually compress. Ratio on text files or synthetic data is a14 secondary signal.152. **Decompression throughput.** Pages are compressed once when they go16 cold but restored on demand (scrollback access, search, inspection), so17 restore latency is felt directly.183. **Compression throughput.** Runs on idle pages in the background; being19 fast is nice, being slow is tolerable.2021## Testing2223- Targeted tests: `zig build test -Dtest-filter=<codec>`24- Prefer `zig build test-lib-vt -Dtest-filter=<codec>` when practical;25 this code ships in libghostty-vt.26- Codecs must keep building for `wasm32-freestanding` (libghostty-vt):27 no libc, no `src/simd` (Highway) dependencies. Verify with28 `zig build -Demit-lib-vt -Dtarget=wasm32-freestanding -Doptimize=ReleaseSmall`.29- Every codec needs a differential property suite: round-trip identity,30 an independent format walker, wrong-size output rejection, and31 corruption/truncation decoding. Keep a light version in normal unit32 tests and gate the exhaustive version behind an environment variable so33 the default test suite stays fast.3435## Verifying Correctness3637- Decoders must be memory-safe for arbitrary input bytes. Every blind or38 wide copy needs a stated margin argument bounding it by the output39 buffer; keep those arguments in comments next to the code.40- Writing scratch bytes past a copy's logical end is safe only inside the41 output buffer, because in-order decoding rewrites them before any match42 can read them back. Do not weaken the exact-size output contract.43- When a change should not alter compressor output, prove it: compare44 encoded sizes (or a sequence-count fingerprint) on the same corpus45 before and after. Ratio drift is a functional change, not noise.4647## Benchmarking4849- Use `ghostty-bench +page-compression` (see `src/benchmark/AGENTS.md`50 for the general workflow). Modes: `compress`, `decompress`, `store`,51 and `report` for ratio.52- Build: `zig build -Demit-bench -Doptimize=ReleaseFast -Demit-macos-app=false`53- The most representative corpus is a raw dump of real page backing54 memory, chunked at the page size (400 KiB on ReleaseFast targets).55 Supplement with a text corpus and random bytes for worst cases, but56 weigh page corpora highest per the priorities above. Keep corpora57 outside the repository and reuse identical files across comparisons.58- `ghostty-bench +scrollback-compression` measures the PageList59 transitions around the codec rather than the codec itself.60- For fast iteration, keep codecs dependent only on `std` so a standalone61 harness can build them directly with `zig build-exe -O ReleaseFast` and62 time the codec in-process (report min-of-N, verify round-trips).63- Measure one change at a time and re-measure the final state; run-to-run64 noise is a few percent, so re-run before believing small deltas.6566## Performance Notes6768- Real page data decodes as millions of tiny operations (in LZ4: mostly69 zero literals plus a 4-18 byte match). Per-item overhead dominates, so70 branch-light fast paths with blind fixed-size copies win.71- Wide copies are the only SIMD that pays here. Vectorized compares and72 other wide-stride tricks measured as net losses because matches are73 short; prefer the simple word loop unless a measurement on page corpora74 says otherwise.75- `@memcpy` beats stride loops only for long copies (roughly 64 bytes and76 up); call overhead loses below that.7778## LZ4 Specific7980- The codec is `lz4.zig`, an allocation-free raw block (not frame)81 implementation. Blocks do not carry their decoded size; callers supply82 an exact-size output buffer.83- Tests: `zig build test -Dtest-filter=lz4`. The differential suite is84 `lz4_differential.zig`; run the exhaustive version for any codec85 change:86 `GHOSTTY_LZ4_SLOW=1 zig build test -Dtest-filter="lz4 differential"`87- The compressor must keep the standard format restrictions (final five88 bytes literal, matches start at least twelve bytes before the end) so89 blocks stay consumable by optimized external decoders. The differential90 walker checks this.91
Also in ghostty-org/ghostty
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| ghostty-org/ghosttymacos/AGENTS.md · 59k | AGENTS.md | style | 51/100 | 3 days ago | |
| ghostty-org/ghosttysrc/benchmark/AGENTS.md · 59k | AGENTS.md | buildstyledo-notagent-behaviour | 74/100 | 3 days ago | |
| ghostty-org/ghosttysrc/terminal/snapshot/AGENTS.md · 59k | AGENTS.md | no sections | 16/100 | 3 days ago | |
| ghostty-org/ghosttytest/fuzz-libghostty/AGENTS.md · 59k | AGENTS.md | style | 64/100 | 3 days ago | |
| ghostty-org/ghosttysrc/inspector/AGENTS.md · 59k | AGENTS.md | no sections | 16/100 | 3 days ago | |
| ghostty-org/ghosttysrc/terminal/apc/glyph/AGENTS.md · 59k | AGENTS.md | style | 20/100 | 3 days ago | |
| ghostty-org/ghosttysrc/terminal/c/AGENTS.md · 59k | AGENTS.md | styleapi | 43/100 | 3 days ago | |
| ghostty-org/ghosttyAGENTS.md · 59k | AGENTS.md | lint-formatstylearchgit+1 | 76/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| vllm-project/vllmAGENTS.md · 88k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 3 days ago | |
| netdata/netdatasrc/go/plugin/ibm.d/AGENTS.md · 80k | AGENTS.md | buildtestlint-formatarch+3 | 99/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| duckdb/duckdbAGENTS.md · 40k | AGENTS.md | buildtestlint-formatstyle+8 | 96/100 | today | |
| dragonflydb/dragonflyAGENTS.md · 31k | AGENTS.md | setupbuildtestlint-format+10 | 96/100 | 2 days ago | |
| steipete/CodexBarAGENTS.md · 20k | AGENTS.md | buildteststylearch+4 | 93/100 | 3 days ago | |
| buzz-language/buzzAGENTS.md · 1.5k | AGENTS.md | styledo-not | 93/100 | 3 days ago |
