Skip to content

Odoc compress payloads - #1486

Open
jonludlam wants to merge 7 commits into
ocaml:masterfrom
jonludlam:odoc-compress-payloads
Open

Odoc compress payloads#1486
jonludlam wants to merge 7 commits into
ocaml:masterfrom
jonludlam:odoc-compress-payloads

Conversation

@jonludlam

Copy link
Copy Markdown
Member

Note: this branch includes the changes in both #1479 and #1375

The last commit in this PR enables compression on odoc/odocl files if the compiler supports it. This results in a big drop in file sizes (around 4-5 times smaller).

jonludlam and others added 7 commits September 3, 2026 10:56
Before this change, the magic string was read by reading the number
of bytes we're expecting to read based on our magic string. If ours
happens to be a prefix of the real one (e.g. ours is
'odoc-3.1.0' and the real one is 'odoc-3.1.0-2-g12345789') then
the check was succeeding and then the subsequent unmarshalling was
failing.

This fixes that by writing the length too, so we always unmarshal
the right length.
These were introduced in 2c2ff6c to replace polymorphic compare and hash.
Recent measurements show that these don't have a useful effect any more,
and they cost a lot when storing the odoc files on disk as there's no
sharing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
No need to keep the record now that ikey/hash are gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Structurally equal paths used to be shared, via a memo in Lang_of that
d1c0bad stopped applying and d90903a then removed. Repeated paths
have been written out in full since. Hash-cons the converted paths
instead, which doesn't need the maps and so shares across a whole run.

Path.Resolved.Module gets the equal/hash/Hashtbl that Identifier already
has, with the same hashing parameters.

aliaschain.t goes from 1.1MB to 33KB, and peak RSS while linking from
70MB to 43MB; a full `odoc_driver core` run is ~14% smaller.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Route the marshalling in Odoc_file through the compiler's own Compression
module (compiler-libs.common, already a dependency), the same mechanism it
uses for .cmt/.cmti. Payloads are compressed when the compiler was built
with zstd support and fall back to plain Marshal otherwise.

Add a marker in the magic that states whether compression is being used.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jonludlam
jonludlam force-pushed the odoc-compress-payloads branch from ecc681e to b64080f Compare September 3, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant