Compression: add zstd, switch backend to bytesrw, compress by default in serve mode#303
Open
balat wants to merge 6 commits into
Open
Compression: add zstd, switch backend to bytesrw, compress by default in serve mode#303balat wants to merge 6 commits into
balat wants to merge 6 commits into
Conversation
Replace the hand-written gzip framing (header, CRC32, trailer) and the camlzip Zlib calls with bytesrw writer filters. gzip and deflate (zlib format) behaviour is unchanged; the streaming model now bridges the synchronous bytesrw compressor to the Lwt output through an in-memory buffer flushed after each chunk.
Negotiate the "zstd" Content-Encoding (RFC 8878) alongside gzip and deflate, using bytesrw.zstd. zstd is preferred over gzip and deflate at equal qvalue.
Add a compression registry mirroring the static-server one. The Deflatemod extension publishes a compression instruction with safe defaults (text-based content types), loaded on demand by serve mode and applied after the file server. Matches the on-the-fly compression of `caddy file-server`.
Assert per-codec Content-Encoding (gzip, deflate, zstd) and the zstd preference in deflatemod.t, and that serve mode compresses by default.
Update the Deflatemod manual page for the zstd content-encoding, the codec preference order, the bytesrw dependency, the lack of a Brotli binding, and on-by-default compression in serve mode. Add a CHANGES entry.
Julow
approved these changes
Jun 26, 2026
Julow
left a comment
Contributor
There was a problem hiding this comment.
Very nice! Do you have an idea of the changes in performances ?
Member
Author
|
No :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves Ocsigen Server's content compression, in the spirit of the recent
quick-wins bringing it closer to mainstream static servers (Caddy, nginx).
deflate, preferred at equal qvalue.
bytesrw(a single,modern, composable writer-filter abstraction for gzip/deflate/zstd). This
removes ~90 lines of hand-written gzip framing (header, CRC32, trailer) and
drops the camlzip dependency (it was used nowhere else).
(
ocsigenserver ./public), via a small registry mirroring the static-serverone, so it matches
caddy file-server.Brotli is intentionally not included: there is currently no maintained
OCaml 5 binding to libbrotli (the
brotliopam package requiresocaml < 4.10).Left as a follow-up.
Notes
deflatemaps to the zlib format (Bytesrw_zlib.Zlib), matching theprevious camlzip behaviour (it emitted a zlib header), not raw deflate.
bytesrw,conf-zlib,conf-zstd(system depexts:libzstd-dev,zlib1g-dev).Tests
deflatemod.t: per-codec Content-Encoding (gzip, deflate, zstd) and the zstdpreference.
serve.t: serve mode compresses by default.dune build @checkand@docare green.