Skip to content

Write a build trace for Perfetto with RESCRIPT_TRACE - #9402

Draft
cknitt wants to merge 1 commit into
masterfrom
build-trace
Draft

cknitt wants to merge 1 commit into
masterfrom
build-trace

Conversation

@cknitt

@cknitt cknitt commented Nov 23, 2026

Copy link
Copy Markdown
Member

To see where a build spends its time, set RESCRIPT_TRACE=<file>. The build then writes a trace in the Chrome trace event format when it exits. Open it at ui.perfetto.dev to see a timeline:

  • Main track: a span per dependency graph (parse, compile, namespaces, format) and per scheduler step, plus counters for the tasks that are ready and running.
  • One track per worker slot: a span per compiler request, named after its input file. Its arguments hold the words it allocated and the garbage collections that ran meanwhile. Implementations have child spans for type checking and code generation.

Gaps on the worker tracks while the ready counter is above zero are time lost to scheduling. Long type-checking spans show which modules hold up their dependents.

The typing split comes from a small domain-local hook (Compile_phase_hook in compiler/driver) that Js_implementation calls once typing is done. Worker slots are used instead of domain ids, because each dependency graph starts a new worker pool.

Cost: without the variable, the scheduler checks a flag per step and the compiler calls an empty hook per implementation. Clean builds of tests/tests (690 modules, 10 alternating runs) take 0.28 s with and without this change. With the trace on they take 0.305 s, mostly to write the 1 MB trace file.

New test: rewatch-ocaml/tests/run.sh builds a two-module project with and without the trace. It checks that the JavaScript is the same, and that the trace has the request spans, their typing and code-generation children, the graph span and the counters.

The format is meant for people and may change. Existing REWATCH_* variables will get RESCRIPT_* names in a separate PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

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>
@cknitt

cknitt commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

Copy link
Copy Markdown

Changelog

🚀 New Feature

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

Semantic Diff

1 commit · 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T20:15:06.430128Z 67ea24a 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 67ea24ac9f

ℹ️ 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".

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.21%. Comparing base (449d6e7) to head (67ea24a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
compiler/driver/compile_phase_hook.ml 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9402      +/-   ##
==========================================
- Coverage   82.21%   82.21%   -0.01%     
==========================================
  Files         460      461       +1     
  Lines       65552    65556       +4     
==========================================
+ Hits        53892    53895       +3     
- Misses      11660    11661       +1     
Files with missing lines Coverage Δ
compiler/driver/js_implementation.ml 85.34% <100.00%> (+0.12%) ⬆️
compiler/driver/compile_phase_hook.ml 66.66% <66.66%> (ø)
🚀 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

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 636,979,225 → 637,000,404 (±0.00%).

Generated projects: 629,030,670 → 629,063,621 (+0.01%).

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

Instructions

In total: 9,221,381,560 → 9,221,393,321 (±0.00%).

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

Output size

In total: 25,976,823 → 25,976,823 (±0.00%).

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

Pull request 67ea24a compared with base 449d6e7 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 67ea24a

@github-actions

Copy link
Copy Markdown

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