Skip to content

Prototype writing build outputs on a background domain - #9406

Draft
cknitt wants to merge 1 commit into
build-tracefrom
background-writer
Draft

cknitt wants to merge 1 commit into
build-tracefrom
background-writer

Conversation

@cknitt

@cknitt cknitt commented Nov 24, 2026

Copy link
Copy Markdown
Member

Prototype for measuring: this is opt-in and only meant to find out whether writing outputs off the compiler workers speeds up real builds.

A build trace (#9402) of a real project showed compiler workers spending 16–25% of their time publishing outputs. Each write also took twice as long with 8 workers writing at once.

With RESCRIPT_BACKGROUND_WRITES=1, the held outputs (.ast, .iast, .cmi, .cmt, .cmti) go to a queue that one writer domain writes in order, and the workers go back to compiling:

  • The build file store keeps serving the contents until they're on disk. The writer's atomic write doesn't make the store forget the path, and a typed tree leaves the store only once it's written, because gentype reads it from disk.
  • The parse and compile phases wait for the queue when they end. The first write error fails the build there.
  • Without the variable, every write runs right away, as before.

With RESCRIPT_TRACE, every write is a span named after its file, with its size and kind. It sits on a writer track, or inside the worker's publish span when the writer is off.

On tests/tests (690 modules, linux-arm64):

  • Clean builds with the writer leave the same 3,484 output files.
  • They take 0.270 s instead of 0.295 s (median of 10).
  • A write takes 47–115 µs on the writer and 169–201 µs with 8 workers writing. Most of that is per file, not per byte.
  • The build never waited for the writer.

Open questions before this could become the default:

  • Whether one writer keeps up on slower file systems.
  • Cheaper atomic writes: create the temporary file once with its final permissions, instead of creating it, closing it, changing its permissions and opening it again.
  • Whether a clean build needs .cmt files at all.

Stacked on #9402.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QchYQ7itFLVLUmZ368okjH

A trace of a real project showed compiler workers spending 16-25% of their
time publishing outputs, and each write taking twice as long with 8 workers
writing at once. With RESCRIPT_BACKGROUND_WRITES=1, the held outputs (.ast,
.iast, .cmi, .cmt, .cmti) now go to a queue that one writer domain writes in
order, so workers go back to compiling. The build file store keeps serving
the contents until they are on disk: the writer's atomic write does not make
the store forget the path, and a typed tree leaves the store only once it is
written. The parse and compile phases wait for the queue when they end, and
the first write error fails the build there. Without the variable every
write runs right away, as before.

With RESCRIPT_TRACE, every write is now a span named after its file with its
size and kind, on the writer's track or inside the worker's publish span.

On tests/tests (690 modules), clean builds with the writer leave the same
3484 output files and take 0.270 s instead of 0.295 s (median of 10). A
write takes 47-115 us on the writer and 169-201 us with 8 workers writing,
and the build never waited for the writer.

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 added this pull request to stack #9407 November 24, 2026 14:36
@github-actions

Copy link
Copy Markdown

Changelog

🏠 Internal

  • Add an opt-in background writer for build outputs (RESCRIPT_BACKGROUND_WRITES=1), to measure whether writing files off the compiler workers speeds up builds.

Semantic Diff

1 commit · Full page

Prototype writing build outputs on a background domain

44e06fb · cknitt + Claude · Nov 24, 2026, 14:35 UTC

A trace of a real project showed compiler workers spending 16-25% of their time publishing outputs, and each write taking twice as long with 8 workers writing at once. With RESCRIPT_BACKGROUND_WRITES=1, the held outputs (.ast, .iast, .cmi, .cmt, .cmti) now go to a queue that one writer domain writes in order, so workers go back to compiling. The build file store keeps serving the contents until they are on disk: the writer's atomic write does not make the store forget the path, and a typed tree leaves the store only once it is written. The parse and compile phases wait for the queue when they end, and the first write error fails the build there. Without the variable every write runs right away, as before.

With RESCRIPT_TRACE, every write is now a span named after its file with its size and kind, on the writer's track or inside the worker's publish span.

On tests/tests (690 modules), clean builds with the writer leave the same 3484 output files and take 0.270 s instead of 0.295 s (median of 10). A write takes 47-115 us on the writer and 169-201 us with 8 workers writing, and the build never waited for the writer.

@github-actions

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 637,002,064 → 637,233,177 (+0.04%).

Generated projects: 629,067,623 → 629,496,976 (+0.07%).

Benchmark Base Head Change
build/Namespace/clean 84,191,871 84,536,023 +0.41%

Instructions

In total: 9,221,409,971 → 9,221,409,971 (±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 44e06fb compared with base e15e3b3 in this run.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.21%. Comparing base (e15e3b3) to head (44e06fb).

Additional details and impacted files
@@               Coverage Diff               @@
##           build-trace    #9406      +/-   ##
===============================================
- Coverage        82.22%   82.21%   -0.02%     
===============================================
  Files              462      461       -1     
  Lines            65577    65556      -21     
===============================================
- Hits             53919    53895      -24     
- Misses           11658    11661       +3     

see 3 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.

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 44e06fb

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