Semantic Diff

#9408 Write build artifacts with fewer file-system calls

3 commits

449d6e7741a718a86c36c44df9b9db46eeec53b1..pr-9408

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.

3eb0b7ce3 · cknitt + Claude · Nov 24, 2026, 16:36 UTC

Write build artifacts with fewer file-system calls

A clean build writes thousands of artifacts through write_file_atomic. Each write created the temporary file, closed it, set its mode by path, opened it again to write and then renamed it. Now the temporary file is created once with O_EXCL, given mode 0644 with fchmod, written through that descriptor, closed and renamed. Windows has no fchmod, so the new Platform.set_file_permissions does nothing there.

On tests/tests with one compiler worker, the publish spans take 74 ms instead of 90 ms. With 8 workers they stay at about 385 ms.

Review

  • Does a failed write still remove its temporary file? Yes, any exception closes the descriptor if it is still open, removes the file and re-raises. A test covers a missing directory and a directory as the destination.