Repository navigation
encode: add standard benchmark and conformance harness - #7804
Conversation
goos: darwin
goarch: arm64
pkg: github.com/caddyserver/caddy/v2/modules/caddyhttp/encode
cpu: Apple M4 Pro
BenchmarkEncodeHandlerCorpus/payload-html/encoder-gzip/compress-level-1-12 4346 26835 ns/op 2708.61 MB/s 6242 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-html/encoder-gzip/compress-level-5-12 3162 53851 ns/op 1349.74 MB/s 9404 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-html/encoder-gzip/compress-level-9-12 435 277501 ns/op 261.93 MB/s 70945 B/op 13 allocs/op
BenchmarkEncodeHandlerCorpus/payload-html/encoder-zstd/compress-level-fastest-12 4191 29281 ns/op 2482.33 MB/s 7905 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-html/encoder-zstd/compress-level-default-12 3517 39310 ns/op 1849.00 MB/s 15736 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-html/encoder-zstd/compress-level-best-12 531 225351 ns/op 322.54 MB/s 1836202 B/op 14 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-gzip/compress-level-1-12 874 156258 ns/op 1878.11 MB/s 40567 B/op 11 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-gzip/compress-level-5-12 556 224974 ns/op 1304.46 MB/s 57672 B/op 12 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-gzip/compress-level-9-12 134 826199 ns/op 355.20 MB/s 216392 B/op 20 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-zstd/compress-level-fastest-12 1260 117385 ns/op 2500.06 MB/s 44849 B/op 13 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-zstd/compress-level-default-12 805 184375 ns/op 1591.70 MB/s 135120 B/op 15 allocs/op
BenchmarkEncodeHandlerCorpus/payload-json/encoder-zstd/compress-level-best-12 126 837183 ns/op 350.54 MB/s 8656840 B/op 31 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-gzip/compress-level-1-12 1394 140602 ns/op 1122.25 MB/s 28431 B/op 11 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-gzip/compress-level-5-12 586 241300 ns/op 653.92 MB/s 76045 B/op 12 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-gzip/compress-level-9-12 202 559961 ns/op 281.79 MB/s 174517 B/op 17 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-zstd/compress-level-fastest-12 1537 118371 ns/op 1333.03 MB/s 40778 B/op 13 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-zstd/compress-level-default-12 774 197076 ns/op 800.66 MB/s 228731 B/op 16 allocs/op
BenchmarkEncodeHandlerCorpus/payload-js/encoder-zstd/compress-level-best-12 99 1031647 ns/op 152.95 MB/s 10853508 B/op 36 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-gzip/compress-level-1-12 9120 14393 ns/op 3734.72 MB/s 2521 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-gzip/compress-level-5-12 6092 20347 ns/op 2641.79 MB/s 5157 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-gzip/compress-level-9-12 504 228173 ns/op 235.58 MB/s 86043 B/op 13 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-zstd/compress-level-fastest-12 9782 15447 ns/op 3479.86 MB/s 3431 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-zstd/compress-level-default-12 7218 18212 ns/op 2951.48 MB/s 9243 B/op 10 allocs/op
BenchmarkEncodeHandlerCorpus/payload-css/encoder-zstd/compress-level-best-12 1580 122157 ns/op 440.02 MB/s 543273 B/op 11 allocs/op
PASS
ok github.com/caddyserver/caddy/v2/modules/caddyhttp/encode 12.242s |
There was a problem hiding this comment.
This is the mostly right intermediate step to me with benchmarking and conformance coverage first, separate from whether Brotli belongs in core.
Two things I would want fixed before merge:
- Trailing whitespace in
modules/caddyhttp/encode/testdata/caddy_home.html - I am not sure we should lock in the current
206 Partial Contentbehaviour as “conformance”. If a range response is encoded,Content-Rangeneeds careful handling because the original byte range may no longer describe the transferred encoded representation. I would either make range responses bypass encoding in the test expectation or explicitly assert the intendedContent-Rangebehaviour.
Once those are addressed, I think this is useful groundwork for #7699 without us prematurely adding Brotli to core.
|
Thanks for the review @steadytao!
Is this file failing a linter? I was thinking we'd want to preserve the source data (caddyserver.com as of June 2026) as opposed to editing and correcting it?
Nice find! It seems like you found a bug in I think range responses on pre-compressed static files should be valid and easy for Caddy to serve so I would suggest a new test in |
This is a shared encode_test harness with HTML/JSON/JS/CSS payloads taken from caddyserver.com Benchmarks: - BenchmarkStandardEncodingPayloads: raw encoder NewEncoder/Write/Close path - BenchmarkEncodeHandlerCorpus: full Encode.ServeHTTP middleware path - Grid: 4 payloads × gzip levels 1/5/9 × zstd fastest/default/best - Each subtest runs with 4 parallel workers; compare runs on MB/s and allocs/op Conformance tests: - Encoder contract: Reset, Flush, Close, and pool-style Reset-after-Close reuse - Corpus HTTP encoding: Content-Encoding, Vary, ETag suffix, header stripping - Response semantics: minimum_length, 304, HEAD, range, WebSocket bypass, If-None-Match rewrite, Cache-Control no-transform, content-type matcher rejection
451d549 to
42de932
Compare
No, just
Agreed. Dynamic I am also going to do one more pass over this before approving since this PR now also includes a small runtime behaviour fix rather than only the harness in |
|
Thanks for the review, and yes, we are now changing |
|
Will get a secondary opinion on this as it is quite a large change 😁 @mholt @francislavoie @mohammed90 @WeidiDeng bumping this your way for opinions. |
|
Looks fine to me, just added tests and benchmarks. |
mholt
left a comment
There was a problem hiding this comment.
Yeah, I think this is also okay. Big change but it's all tests.
…e-control-no-transform Resolve encode.go to keep upstream's If-None-Match list handling without the no-transform check, drop TestIsEncodeAllowed, and update the no-transform conformance cases added in caddyserver#7804 to expect encoding.
This came from a discussion in #7699 where @steadytao wrote:
I think the intent is basically: how can we assess a new encoder without a sense of correct handling.
So this is a shared encode_test harness with HTML/JSON/JS/CSS payloads taken from caddyserver.com website.
Benchmarks:
Conformance tests:
Assistance Disclosure
I wrote the plan based on @steadytao post on #7699 and had Codex GPT 5.5-xhigh and Composer 2.5 implement my plan.