Skip to content

Stop writing a copy of the .cmi into .cmt and .cmti files - #8774

Merged
cknitt merged 3 commits into
perf-js-shakefrom
slim-cmt
Oct 10, 2026
Merged

cknitt merged 3 commits into
perf-js-shakefrom
slim-cmt

Conversation

@cknitt

@cknitt cknitt commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Stacked on #8773.

Like OCaml, the compiler wrote a full copy of the module's .cmi in front of the cmt infos in every .cmti, and in every .cmt of a module without an interface. This PR stops writing it.

Why the copy was there

This comes from upstream OCaml's -bin-annot design. A .cmt/.cmti pair is meant to describe a compilation unit on its own: the format is "a .cmi, then the cmt infos", so a tool that only has the annotation files (documentation generators, indexers) can get both the typed tree and the exact signature with its CRCs from one file. That is why .cmti files always embed the .cmi (it comes from the .mli), .cmt files embed it only when there is no .mli, and Cmt_format.read accepts .cmi, .cmt and .cmti alike. cmt_interface_digest records the CRC of the embedded .cmi, so that a tool can check that an annotation file matches the interface it is used with.

Why ReScript doesn't need it

  • The .cmi is always available next to the .cmt: bsc writes it to lib/bs and rewatch copies it to lib/ocaml.
  • Nothing reads the copy. Analysis, reanalyze, gentype and rescript-tools use Cmt_format.read_cmt and only look at the cmt infos. The one tool that needs a signature, analysis' createInterface, reads the .cmi file.
  • Nothing reads cmt_interface_digest (the playground already sets it to None).

So the copy was pure cost: an extra marshalled signature in every .cmti and interface-less .cmt, a re-read of the partially written file to compute its digest, and an unmarshal of the copy on every read_cmt. The only thing given up is self-containment for an external tool that reads just .cmt/.cmti and wants the signature from them; nothing in this repository or the editor tooling does that.

Compatibility

There is no format change: Cmt_format.read already accepts files with and without the copy (it dispatches on the leading magic number), so files from older compilers keep working, and no magic number bump is needed. cmt_interface_digest is now always None; removing the field would change the marshalled record. save_cmt no longer takes the cmi.

Measurements

Runtime and Belt lib/ocaml:

Before After
.cmt (147 files) 7.18 MB 6.63 MB (−7.6%)
.cmti (85 files) 3.85 MB 2.53 MB (−34%)

.cmt files shrink less because modules with an interface never had the copy there.

rescript-tools reanalyze -dce on the runtime package (lib/ contains the lib/bs copies too: 12.2 → 9.5 MB of .cmt/.cmti), same binary, old vs. new files: identical output, major-heap words −6.7% (the unmarshalled copies), CPU time within noise since the analysis itself dominates. Compile time and allocation are unchanged (same method as #8769).

🤖 Generated with Claude Code

@cknitt
cknitt added this pull request to stack #8775 October 10, 2026 10:17
@cknitt

cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T10:49:23.075246Z 3dccd48 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23e70a181e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md
Comment thread compiler/ml/cmt_format.mli
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.64%. Comparing base (36d26f2) to head (09b9a2a).

Additional details and impacted files
@@                Coverage Diff                @@
##           perf-js-shake    #8774      +/-   ##
=================================================
- Coverage          80.66%   80.64%   -0.02%     
=================================================
  Files                463      463              
  Lines              62755    62755              
=================================================
- Hits               50619    50609      -10     
- Misses             12136    12146      +10     
Files with missing lines Coverage Δ
compiler/core/js_implementation.ml 84.40% <100.00%> (ø)
compiler/ml/cmt_format.ml 100.00% <ø> (ø)
compiler/ml/cmt_format_common.ml 72.72% <ø> (-5.46%) ⬇️
compiler/ml/typemod.ml 73.76% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cknitt

cknitt commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 3dccd48822

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review October 10, 2026 10:50
@cknitt
cknitt requested a review from cristianoc October 10, 2026 10:50
@pkg-pr-new

pkg-pr-new Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8774

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8774

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8774

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8774

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8774

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8774

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8774

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8774

commit: 09b9a2a

cknitt and others added 3 commits October 10, 2026 15:22
Nothing reads it; tools load the .cmi itself. Files with the copy can
still be read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt merged commit b497cb6 into master Oct 10, 2026
24 checks passed
@cknitt
cknitt deleted the slim-cmt branch October 10, 2026 15:42
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.

2 participants