Skip to content

Proof of concept: build without artifact files - #9409

Draft
cknitt wants to merge 4 commits into
masterfrom
no-artifacts-poc
Draft

cknitt wants to merge 4 commits into
masterfrom
no-artifacts-poc

Conversation

@cknitt

@cknitt cknitt commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Based on #9402: this branch contains #9402's two commits, so it targets master to get CI and preview packages; only the last commit belongs to this PR.

This is a proof of concept. With RESCRIPT_NO_ARTIFACTS=1, the build system writes only the JavaScript, like a Rust port of the compiler would. ASTs, interfaces, .cmj files and namespace maps stay in memory for the life of the process. Without the variable nothing changes.

What the mode does

  • rescript build builds everything in every new process, since nothing is kept on disk.
  • rescript watch keeps the artifacts in memory across rebuilds. Incremental rebuilds compile the same modules as in the normal mode.
  • Only the JavaScript output (and source maps), js-post-build hooks, the lock files and .compiler.log touch the disk. No .ast, .iast, .cmi, .cmj, .cmt, .cmti, .mlmap, compiler-info.json or .sourcedirs.json are written.
  • The runtime's shipped interfaces are still read from disk.

What changed

  • Build_file_store can keep chosen paths in memory only. Each such file has a modification time, set when it is written or published with new contents. So the freshness rules work as they do with files on disk.
  • These files survive the end of a build. Everything read from disk is dropped as before, and the generation still changes every build, so the type checker's caches start over.
  • Held writes of a failed request fall back to the file kept before them. forget keeps a file in memory, like a file on disk; the new remove deletes it.
  • The build system marks the artifact directories of the packages it builds as memory only (new No_artifacts module).
  • It compiles with -bs-no-bin-annot. An empty typed tree in memory marks a module compiled.
  • Compile_assets lists the store instead of the directories. Dating an AST back changes its time in memory. The disk fallbacks in Build_freshness and Ast_header are off in this mode.
  • It skips compiler-info.json, .sourcedirs.json and the clean after a compiler change.
  • The compiler reads the namespace map through the store (Js_implementation.implementation_map), so it can live in memory too.

Results (linux-arm64)

tests/tests (690 modules), 10 alternating clean builds per mode, /usr/bin/time:

elapsed median / min user sys peak RSS
normal 0.29 / 0.28 s 0.98 s 0.38 s 507 MB
no artifacts 0.23 / 0.22 s 0.87 s 0.21 s 486 MB
normal, 1 domain 1.05 / 1.05 s 0.89 s 0.16 s 123 MB
no artifacts, 1 domain 0.89 / 0.88 s 0.80 s 0.08 s 119 MB

Part of the gain comes from not making typed trees at all.

The JavaScript of a clean build is the same in both modes (md5 of every .mjs).

A watch of the same project: an interface change of test_utils.res compiled 211 modules in both modes, and an implementation-only change then compiled 2. Peak RSS of the watch process was 533 MB, against 599 MB in the normal mode. The JavaScript matched a clean build.

A watch scenario on a small namespaced project gave the same compiles in both modes: an implementation change without an interface change does not recompile dependents, an interface change does, a type error and its fix recover, an added file is compiled, a deleted file's JavaScript is removed, and a module that names it then fails with "can't be found". The final JavaScript matched a clean normal build.

The integration suite (rewatch/tests), run test by test with the variable set: 46 of 60 tests pass, among them all watch tests but one. The 14 failures are expected for this proof of concept:

  • 10 compile tests (03–09, 11, 16, 23) compare output such as "Cleaned 1 stale module, Parsed 2 source files" or check that nothing recompiles. Every new process builds all 472 modules instead.
  • The rename and remove tests (03–08) and features/04 also run a new process after the change. It has no ASTs that tell which source wrote the old JavaScript, so that file stays on disk. Inside a watch session it is removed.
  • compile/21 and watch/04 change the package-specs. The outputs of the previous specs are found only through compiler-info.json, which this mode does not write.
  • gentype/01 needs typed trees.

Known limitations

  • Editor tooling and gentype don't work in this mode: there are no typed trees, .cmi files or .sourcedirs.json on disk.
  • Every new rescript build is a full build.
  • A new process does not remove the JavaScript of sources that were renamed or deleted since the last build, nor outputs of a previous package-specs. A watch session does, except for a package-specs change.
  • All ASTs, interfaces and .cmj files of the project stay in memory. For tests/tests this was less than the typed trees the normal mode makes.
  • The variable is read once per process; mixing modes on one project is safe, because memory mode never reads artifacts from disk, but a normal build afterwards starts from whatever the last normal build left.

New tests

  • rewatch-ocaml/tests/run.sh builds the namespace and dependency fixtures in both modes, and checks that the JavaScript is the same and that no artifact files are written.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

cknitt and others added 3 commits November 23, 2026 20:12
To see where a build spends its time, RESCRIPT_TRACE=<file> now makes the
build write a Chrome trace event file when it exits, which Perfetto
(ui.perfetto.dev) shows as a timeline:

- The main track has a span per dependency graph (parse, compile,
  namespaces, format) and per scheduler step, and counters for the tasks
  that are ready and running.
- Each worker slot has a track with a span per compiler request, named
  after its input file, with its allocated words and the garbage
  collections during it as arguments. Implementations get child spans for
  type checking and code generation, from a domain-local hook that
  Js_implementation calls once typing is done.

Times are whole microseconds, so spans that share an end point nest
exactly. A command that records nothing, such as a clean, leaves an
earlier trace alone.

Without the variable, the scheduler only checks a flag per step and the
compiler calls an empty hook per implementation. Clean builds of
tests/tests take the same time as before (0.28 s); with the trace on they
take 0.305 s, mostly for writing its 1 MB file. A test in
rewatch-ocaml/tests/run.sh checks the trace's spans and nesting and that
traced builds write the same JavaScript.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH
Signed-off-by: Christoph Knittel <ck@cca.io>
A trace of a real project showed workers spending 20-25% of their time in
tasks but outside compiler requests. That time is the task's result handler,
which publishes the files the request wrote; it now gets a "publish" span
after the request on the worker's track. On tests/tests it takes 398 ms
against 1349 ms of compiler requests. The trace test checks that the span
follows each implementation's request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH
Signed-off-by: Christoph Knittel <ck@cca.io>
Why:
    A proof of concept of a build that, like a Rust port of the compiler
    would, writes only the JavaScript. With RESCRIPT_NO_ARTIFACTS=1 the
    ASTs, interfaces, .cmj files and namespace maps of the packages being
    built stay in memory for the whole process. A new process builds
    everything again; a watch session keeps them across rebuilds. Without
    the variable nothing changes.

Build_file_store can now keep selected paths in memory only. Each has a
modification time, set when it is written or published changed, so the
freshness rules work as with files on disk. These files survive the end
of a build, while everything read from disk is dropped as before and the
generation still changes, so type-checker caches start over each build.
Held writes of a failed request fall back to the file kept before them.
forget keeps such a file, like a file on disk, and the new remove deletes
it.

The build system marks the artifact directories of the packages it
builds as memory only; the runtime's shipped interfaces are still read
from disk. In this mode it compiles with -bs-no-bin-annot, and an empty
typed tree in memory marks a module compiled. The artifact index lists
the store instead of the directories, and dating an AST back changes its
time in memory. It skips compiler-info.json, .sourcedirs.json and the
clean after a compiler change. The compiler now reads the namespace map
through the store.

On tests/tests (690 modules, linux-arm64), a clean build takes 0.23 s
instead of 0.29 s (median of 10), and 0.89 s instead of 1.05 s with one
domain. Peak memory is a little lower, as no typed trees are made.
Editor tooling and gentype don't work in this mode.

A test in rewatch-ocaml/tests/run.sh builds a namespace and a dependency
in both modes, and checks that the JavaScript is the same and that no
artifact files are written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Changelog

🚀 New Feature

  • Write a timeline of the build, viewable in Perfetto, to the file that RESCRIPT_TRACE names.

🏠 Internal

  • Add an experimental build mode, RESCRIPT_NO_ARTIFACTS=1, that keeps ASTs,
    interfaces and other artifacts in memory and writes only the JavaScript.

Semantic Diff

4 commits · Full page

Write a build trace for Perfetto with RESCRIPT_TRACE

67ea24a · cknitt + Claude · Nov 23, 2026, 20:08 UTC

To see where a build spends its time, RESCRIPT_TRACE=<file> now makes the build write a Chrome trace event file when it exits, which Perfetto (ui.perfetto.dev) shows as a timeline:

- The main track has a span per dependency graph (parse, compile, namespaces, format) and per scheduler step, and counters for the tasks that are ready and running. - Each worker slot has a track with a span per compiler request, named after its input file, with its allocated words and the garbage collections during it as arguments. Implementations get child spans for type checking and code generation, from a domain-local hook that Js_implementation calls once typing is done.

Times are whole microseconds, so spans that share an end point nest exactly. A command that records nothing, such as a clean, leaves an earlier trace alone.

Without the variable, the scheduler only checks a flag per step and the compiler calls an empty hook per implementation. Clean builds of tests/tests take the same time as before (0.28 s); with the trace on they take 0.305 s, mostly for writing its 1 MB file. A test in rewatch-ocaml/tests/run.sh checks the trace's spans and nesting and that traced builds write the same JavaScript.

Show publishing as a span in the build trace

e15e3b3 · cknitt + Claude · Nov 24, 2026, 07:56 UTC

A trace of a real project showed workers spending 20-25% of their time in tasks but outside compiler requests. That time is the task's result handler, which publishes the files the request wrote; it now gets a "publish" span after the request on the worker's track. On tests/tests it takes 398 ms against 1349 ms of compiler requests. The trace test checks that the span follows each implementation's request.

Build without artifact files when RESCRIPT_NO_ARTIFACTS=1

07b7b0a · cknitt + Claude · Nov 24, 2026, 18:12 UTC

Why

A proof of concept of a build that, like a Rust port of the compiler would, writes only the JavaScript. With RESCRIPT_NO_ARTIFACTS=1 the ASTs, interfaces, .cmj files and namespace maps of the packages being built stay in memory for the whole process. A new process builds everything again; a watch session keeps them across rebuilds. Without the variable nothing changes.

Build_file_store can now keep selected paths in memory only. Each has a modification time, set when it is written or published changed, so the freshness rules work as with files on disk. These files survive the end of a build, while everything read from disk is dropped as before and the generation still changes, so type-checker caches start over each build. Held writes of a failed request fall back to the file kept before them. forget keeps such a file, like a file on disk, and the new remove deletes it.

The build system marks the artifact directories of the packages it builds as memory only; the runtime's shipped interfaces are still read from disk. In this mode it compiles with -bs-no-bin-annot, and an empty typed tree in memory marks a module compiled. The artifact index lists the store instead of the directories, and dating an AST back changes its time in memory. It skips compiler-info.json, .sourcedirs.json and the clean after a compiler change. The compiler now reads the namespace map through the store.

On tests/tests (690 modules, linux-arm64), a clean build takes 0.23 s instead of 0.29 s (median of 10), and 0.89 s instead of 1.05 s with one domain. Peak memory is a little lower, as no typed trees are made. Editor tooling and gentype don't work in this mode.

A test in rewatch-ocaml/tests/run.sh builds a namespace and a dependency in both modes, and checks that the JavaScript is the same and that no artifact files are written.

✨ Let RESCRIPT_WORKER_MINOR_HEAP set the worker minor heap size

e2d6634 · cknitt + Claude · Nov 24, 2026, 20:03 UTC · new

To measure how the size of the workers' minor heaps affects real builds, RESCRIPT_WORKER_MINOR_HEAP sets it in words, optionally with a k or M suffix (for example 16M). Without it the workers keep 4M words. This is a knob for experiments on this proof of concept.

On tests/tests (690 modules, 8 workers, no artifacts), 8M words take 0.22 s instead of 0.23 s for 200 MB more peak memory; larger sizes change nothing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T18:19:49.696907Z 07b7b0a 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: 07b7b0a4ab

ℹ️ 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 on lines +127 to +129
if
(not No_artifacts.enabled)
&& Compiler_info.needs_clean package_context package.config

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate retained artifacts when compiler configuration changes

With RESCRIPT_NO_ARTIFACTS=1, changing compiler-affecting configuration during rescript watch can report a successful rebuild while leaving JavaScript compiled with the old settings. Configuration edits trigger Full_watch_attempt, but the store retains the previous ASTs, interfaces, and compile timestamps, and this guard bypasses the configuration-hash invalidation previously provided by Compiler_info.needs_clean. If source paths and output specifications stay unchanged—for example, when changing JSX settings—the freshness checks in Package_compilation.prepare can therefore skip every module. Preserve the previous configuration fingerprint in memory and invalidate the affected artifacts when it changes; this is separate from the documented limitation concerning cleanup of previous package-spec outputs.

Useful? React with 👍 / 👎.

@cknitt
cknitt changed the base branch from build-trace to master November 24, 2026 18:20
@cknitt cknitt closed this Nov 24, 2026
@cknitt cknitt reopened this Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.64557% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.15%. Comparing base (449d6e7) to head (e2d6634).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
compiler/typing/build_file_store.ml 24.28% 53 Missing ⚠️
compiler/driver/compile_phase_hook.ml 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9409      +/-   ##
==========================================
- Coverage   82.21%   82.15%   -0.06%     
==========================================
  Files         460      462       +2     
  Lines       65552    65628      +76     
==========================================
+ Hits        53892    53918      +26     
- Misses      11660    11710      +50     
Files with missing lines Coverage Δ
compiler/driver/js_implementation.ml 86.20% <100.00%> (+0.98%) ⬆️
compiler/typing/file_io.ml 100.00% <ø> (ø)
compiler/typing/misc.ml 83.33% <100.00%> (ø)
compiler/driver/compile_phase_hook.ml 66.66% <66.66%> (ø)
compiler/typing/build_file_store.ml 66.12% <24.28%> (-25.22%) ⬇️

... and 4 files 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.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 637,411,281 → 638,133,483 (+0.11%).

Generated projects: 629,040,931 → 629,532,435 (+0.08%).

Benchmark Base Head Change
build/shared-edit 72,977,835 73,567,532 +0.81%
build/leaf-edit 13,034,574 13,105,031 +0.54%
build/WideDeps/edit 165,922,819 166,315,139 +0.24%
build/Namespace/edit 7,875,810 7,892,810 +0.22%
build/no-op 9,220,594 9,236,356 +0.17%

Instructions

In total: 9,221,420,275 → 9,222,479,660 (+0.01%).

Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Math.resi 21,298,535 21,345,643 +0.22%
packages/@rescript/runtime/Stdlib_Temporal_PlainDateTime.res 25,529,155 25,580,342 +0.20%
parse/RedBlackTreeNoComments.res 14,489,453 14,516,149 +0.18%
packages/@rescript/runtime/Stdlib_Temporal_PlainDate.res 24,089,865 24,133,144 +0.18%
packages/@rescript/runtime/Stdlib_Temporal_ZonedDateTime.res 31,197,142 31,252,165 +0.18%
packages/@rescript/runtime/Stdlib_List.resi 24,526,656 24,569,411 +0.17%
parse/RedBlackTree.res 14,919,486 14,943,485 +0.16%
packages/@rescript/runtime/Stdlib_String.resi 29,451,051 29,496,604 +0.15%
packages/@rescript/runtime/Stdlib_TypedArray.res 41,309,454 41,365,254 +0.14%
packages/@rescript/belt/src/Belt_Array.resi 33,714,594 33,755,054 +0.12%
1 more change
Benchmark Base Head Change
packages/@rescript/runtime/Stdlib_Date.resi 34,293,433 34,333,636 +0.12%

Output size

In total: 25,987,723 → 25,987,735 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request e2d6634 compared with base aacaf72 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: e2d6634

@github-actions

Copy link
Copy Markdown

To measure how the size of the workers' minor heaps affects real builds,
RESCRIPT_WORKER_MINOR_HEAP sets it in words, optionally with a k or M
suffix (for example 16M). Without it the workers keep 4M words. This is a
knob for experiments on this proof of concept.

On tests/tests (690 modules, 8 workers, no artifacts), 8M words take
0.22 s instead of 0.23 s for 200 MB more peak memory; larger sizes change
nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH
Signed-off-by: Christoph Knittel <ck@cca.io>

This branch has not been deployed

No deployments
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