Semantic Diff

#9409 Proof of concept: build without artifact files

4 commits

449d6e7741a718a86c36c44df9b9db46eeec53b1..pr-9409

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

Write a build trace for Perfetto with RESCRIPT_TRACE

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.

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

Show publishing as a span in the build trace

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.

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

Build without artifact files when RESCRIPT_NO_ARTIFACTS=1

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.

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

Let RESCRIPT_WORKER_MINOR_HEAP set the worker minor heap size

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.