Semantic Diff

#9402 Write a build trace for Perfetto with RESCRIPT_TRACE

1 commit

449d6e7741a718a86c36c44df9b9db46eeec53b1..pr-9402

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.