5.8 KiB
5.8 KiB
AGENTS.md
Guidance for people and coding agents changing this repository. It records conventions and traps learned while working on the decoders and encoders; the README describes the packages themselves.
Checks before sending a change
gofmt,go vet ./...andgo fix -diff ./...(which should report nothing). Code written for specific platforms must be vetted for them too: rungo vetwithGOOS/GOARCHset to each platform it targets.go vetcaches results per package and does not notice edits to files excluded by build tags; use a freshGOCACHEto confirm a stale-looking error.go test ./...with and without-tags=noasm(andnounsafeif you touchedunsafecode), on every architecture whose assembly changed.- Decoder changes: run the fuzzers CI runs (see
.github/workflows/go.yml), also with-tags=noasm,-tags=nounsafeand-asan, for longer than CI does, and for zstd bothFuzzDecodeAlland theNoBMI2variants. - Raising the Go version in the root
go.modbreaks the nested modules (*/_generate,s2/cmd/_s2sx) until they are updated too. In agodirective,1.25sorts before1.25.0, so a dependency that needs1.25.0forces the full form.
Tests
- Put a new test in the existing test file for the code it exercises
(
decoder_test.gofor Reader/DecodeAll behaviour,seqdec_test.gofor sequence execution, and so on), and reuse its helpers. Use table tests for three or more similar cases. - Extend the existing fuzzers (
func Fuzz…) rather than adding parallel harnesses; if a new harness supersedes an old one, remove the old one in the same change. - Prove which path a test or benchmark exercises. A benchmark once ran the
pure-Go sequence decoder instead of the assembly because of how its buffers
were set up. A
panicplanted in the path is a quick check;printlnoutput is easy to miss. sync.Pooldrops about a quarter ofPuts under-raceby design; never assumeGetreturns the lastPut.- Don't add tests whose only purpose is to catch someone deliberately undoing a performance pin (an alignment, say); a comment explaining it is enough.
Performance claims
- Use real data. The maintainer's corpora are at
https://klauspost.com/files/compress/ (logs, JSON, CSV, serialized data,
tar files); put
.zstfiles inzstd/testdata/benchmark-custom/and runBenchmarkDecoderWithCustomFiles. Silesia, enwik and generated data are fine for correctness but are not accepted as evidence for a speed-up. - When a result depends on how the data was compressed, report the levels
separately (for example
SpeedDefaultandSpeedBestCompression). - Anchor
-benchpatterns at every level with$:-bench 'BenchmarkFoo$'also runsBenchmarkFooBarotherwise, which has produced fake gains and regressions. - Code placement alone moves results by about ±2%. For an A/B, insert
PCALIGN $64before everyTEXTin the.sfiles of both builds (measurement only, not committed). - Build both variants as test binaries up front, then run them in turns: one
short
-count 1run of each, repeated for ten or more rounds, swapping which goes first every round (AB, BA, AB, …) so neither build always gets the warmer or colder slot. Never run all of A and then all of B. Clock speed, temperature, cache and page-cache state, and background load drift over a session; alternating spreads that drift over both builds instead of turning it into a difference between them. Pin to one core, use an otherwise idle machine, and compare the pooled results withbenchstat. - Report the number of regressed cases next to the geomean; a small win with no regressions is a different result from a larger one with some.
- No CPU-model-specific code paths or thresholds. A gate for arm64 must be measured on several Neoverse generations (N1, V1, V2, V3), not one core.
Pull requests
- One commit per independent change, with fixups squashed in. Number the changes in the description as "(1) … (sha)" and name the test file for each test.
- Mention each
#NNNonce in prose; refer back in words. - Don't open many PRs against the same area at once; reviewer time is the scarce resource.
- Keep Go comments short; generator and assembly comments can explain in detail.
- Keep private or company-internal references (internal service names, private links, chat or agent-session URLs) out of code, commit messages and PR text.
Assembly is generated
- zstd, huff0 and s2 assembly is generated with the
honeycombio/avo fork of avo from
zstd/_generate,huff0/_generateands2/_generate. Never edit the.sfiles by hand: change the generator, rungo generate -v -xin the_generatedirectory, and commit the regenerated output. CI'sgeneratejob fails if the committed files differ from the generator's output. - The arm64 files are lowered from the same amd64 program by the fork, which
the
_generatemodules import asgithub.com/honeycombio/avo; keep all three on the same fork commit. A change to the generator changes both architectures; build and test both. - When moving the avo pin, regenerate and check the output is byte-identical unless a change is intended, so unrelated printer changes don't slip into a review.
- Never put a label directly on a
PCALIGN(emit thePCALIGNbefore the label). A jump to it makes the amd64 assembler jump to the wrong place (Go ≤ 1.25, golang/go#74648) or loop forever when it has to widen a branch (Go ≥ 1.26, golang/go#81792). Current versions of the avo fork reject it. - Build tags:
noasmselects the pure-Go code andnounsafethe code withoutunsafe. Every assembly orunsafepath needs a portable fallback, and CI runs the default,noasm,nounsafeandnounsafe,noasmbuilds. The library doesn't use cgo.