Skip to content

Start OCaml rewatch watch rebuilds once a save's events settle - #8873

Open
cknitt wants to merge 1 commit into
masterfrom
ocaml-rewatch-watch-settle
Open

cknitt wants to merge 1 commit into
masterfrom
ocaml-rewatch-watch-settle

Conversation

@cknitt

@cknitt cknitt commented Oct 16, 2026

Copy link
Copy Markdown
Member

After the first file event of a save, OCaml rewatch's watch mode always waited 50 ms before rebuilding, to collect the rest of the burst an editor produces. That wait was most of the latency of an edit.

The watcher now starts the rebuild once no event has arrived for 10 ms, and still waits at most 50 ms after the first event. Events arriving later start another build, as before. If the system clock is set back during the wait, the wait ends.

Measured on a Linux VM, from saving a file in tests/tests until its JS output contains the edit:

before after
plain write 66 ms 25 ms
atomic save (write to a temporary file and rename) 77 ms 38 ms

Each save still produces exactly one rebuild. For comparison, Rust rewatch takes 115 ms and 283 ms on the same machine.

The trade-off: an editor whose save events are more than 10 ms apart, such as a format-on-save that writes the file a second time later, can now trigger a second, short rebuild instead of one.

🤖 Generated with Claude Code

Waiting a fixed 50 ms after the first event added most of an edit's
latency. The watcher now starts once no event has arrived for 10 ms, at
most 50 ms after the first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WZbCuRQ1Tn31bnKzLj5e72
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the ocaml-rewatch-watch-settle branch from 9007219 to ce1b818 Compare October 16, 2026 05:59
@cknitt
cknitt marked this pull request as ready for review October 16, 2026 05:59
@pkg-pr-new

pkg-pr-new Bot commented Oct 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

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

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8873

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: ce1b818

@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