Skip to content

Conversation

@cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Dec 29, 2025

ReactiveAnalysisDemo.mov

Summary

Adds a long-lived reanalyze server that keeps reactive analysis state warm across requests, with transparent delegation: rescript-tools reanalyze -json will automatically use the server if it’s running.

Key features

  • Single CLI surface: rescript-tools reanalyze and rescript-tools reanalyze-server
  • No server args: reanalyze-server takes no reanalyze args and always runs in editor mode (-json)
  • Transparent delegation (json-only): delegation happens only for exactly reanalyze -json
    • Disable delegation with RESCRIPT_REANALYZE_NO_SERVER=1
  • Project-root socket: server listens on ./.rescript-reanalyze.sock (in the project root)
  • Works with unmodified VS Code extension: start the server manually, then use “ReScript: Start Code Analyzer” as usual

Results (measured by the harness)

Project Incremental (server) Standalone Speedup
deadcode (311 issues) ~33ms ~28ms ~1.0x
deadcode-benchmark (19K issues) ~57ms ~614ms ~10.8x

Quick Start: try on your project

1) Build this branch

make

2) In your project directory

The analyzer reads compiler artifacts (notably .cmt files), so you need to keep your project compiled.

  • Recommended: run your normal development watch command (so recompilation happens automatically on save).
  • Examples (may differ based on your setup):
    • rescript build -w
    • npx rescript build -w

Then start the server (keep it running in a separate terminal):

# Use the project-local binary:
node_modules/rescript/<platformDir>/bin/rescript-tools.exe reanalyze-server

Now in VS Code run “ReScript: Start Code Analyzer”.

The extension invokes rescript-tools reanalyze -json, which will transparently delegate to the server.

3) Stop the server

Press Ctrl+C in the terminal running reanalyze-server.

If the server crashes and leaves the socket behind, remove it:

rm -f .rescript-reanalyze.sock

Technical notes

  • Socket location: ./.rescript-reanalyze.sock in the project root (avoids macOS UDS path length issues).
  • Delegation is json-only: only reanalyze -json is delegated; other invocations run standalone.

Tests

make test-analysis

cd tests/analysis_tests/tests-reanalyze/deadcode
make test-reactive-server
make test-reactive-server-benchmark

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull 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".

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

- Implement reanalyze-server subcommand that maintains reactive state
- Add reanalyze-server-request client for IPC via Unix socket
- **Transparent delegation**: Regular 'reanalyze' calls automatically use
  the server if running on default socket (/tmp/rescript-reanalyze.sock)
- Works with unmodified VS Code extension - just start the server manually
- Create comprehensive test harness with clean warmup/benchmark phases
- Color-coded logging: [BUILD], [SERVER], [REACTIVE], [STANDALONE], [EDIT]
- Test scenarios: add dead code (+1 issue), make dead code live (-1 issue)
- Results: 2.5x speedup (small project), 10x+ speedup (benchmark)

Usage:
  # Start server (once, in background)
  rescript-editor-analysis reanalyze-server --cwd /path/to/project -- -config -ci -json

  # Now regular reanalyze calls automatically use the server:
  rescript-editor-analysis reanalyze -config -ci -json

Signed-Off-By: Cristiano Calcagno <[email protected]>
@cristianoc cristianoc force-pushed the reactive-server-test-harness branch from 777817b to b68bf16 Compare December 29, 2025 08:30
@cristianoc cristianoc changed the title Add reanalyze-server with reactive test harness Add reanalyze-server with transparent delegation Dec 29, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 29, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8127

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8127

@rescript/win32-x64

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

commit: ebef141

- Log request number, timing, issues, dead/live counts, files processed/cached
- Pass file_stats through runAnalysis to capture processing statistics
- Use locally created mutable stats record instead of global state
- Stats show files processed (new or modified) vs cached (unchanged)
- Default socket lives in project root and is discovered by walking up to rescript.json/bsconfig.json

- Use relative socket name to avoid macOS unix socket path length limits

- Unlink socket on exit and on common termination signals

- Update reanalyze README with VS Code (-json) usage
Move server/IPC/socket-path logic into ReanalyzeServer.ml and keep Reanalyze.ml focused on analysis.
- reanalyze-server runs editor-mode (-json) with no args

- reanalyze delegates to server only for -json

- update reanalyze tests/harness to use rescript-tools

Signed-off-by: Cristiano Calcagno <[email protected]>
Signed-off-by: Cristiano Calcagno <[email protected]>
- Run Gc.compact() after every request to keep memory stable (~257MB)
- Simplify server output to just show live heap: 'mem: 257.0MB'
- Add opt-out via RESCRIPT_REANALYZE_SERVER_SKIP_COMPACT=1 env var
@cristianoc cristianoc requested a review from cknitt January 2, 2026 08:47
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.

2 participants