Skip to content

Optimize VCS diff loading to be up to 98% faster#2586

Open
justsomelegs wants to merge 30 commits intopingdotgg:mainfrom
justsomelegs:t3code/9f93372b
Open

Optimize VCS diff loading to be up to 98% faster#2586
justsomelegs wants to merge 30 commits intopingdotgg:mainfrom
justsomelegs:t3code/9f93372b

Conversation

@justsomelegs
Copy link
Copy Markdown
Contributor

@justsomelegs justsomelegs commented May 8, 2026

What Changed

  • Moved checkpoint filesystem operations behind a generic VCS checkpoint capability instead of scripting Git directly in CheckpointStore.
  • Reworked VcsProcess.run and processRunner onto a shared capturedProcess primitive for one-shot collected process execution.
  • Optimized checkpoint diff generation by:
    • removing redundant checkpoint preflight checks on the diff path
    • resolving the VCS driver once per checkpoint operation
    • using explicit commit peeling (^{commit}) for checkpoint diff refs
  • Added a narrower full-thread diff lookup path and supporting tests.

Why

Opening diffs and switching turns was spending too much time in process execution overhead and checkpoint diff orchestration.

This branch improves that by:

  • reducing per-command process overhead in the hot path
  • moving checkpoint behavior behind the VCS abstraction instead of hand-assembling Git commands in the store
  • reducing Git revision-resolution cost for checkpoint refs in repos with large checkpoint ref namespaces

Benchmark Summary

Synthetic workload used for all numbers below:

  • 24 changed files
  • 690,422 patch bytes
  • 26,137 patch lines

Benchmarks were run sequentially to avoid contention between benchmark loops.

Mean Latency

Metric upstream/main Current branch
checkpointStore.diffCheckpoints 1179.81ms 72.84ms
checkpointDiffQuery.getTurnDiff 1649.32ms 52.05ms
parseTurnDiffFilesFromUnifiedDiff 12.42ms 11.97ms

Tail Latency (p99)

Metric upstream/main Current branch
checkpointStore.diffCheckpoints 2262.90ms 355.04ms
checkpointDiffQuery.getTurnDiff 2937.21ms 191.04ms
parseTurnDiffFilesFromUnifiedDiff 16.43ms 19.63ms

Key Measurements

Compared directly with upstream/main:

  • checkpointStore.diffCheckpoints: 1179.81ms -> 72.84ms mean (16.20x faster, 93.8% lower)
  • checkpointDiffQuery.getTurnDiff: 1649.32ms -> 52.05ms mean (31.69x faster, 96.8% lower)
  • checkpointStore.diffCheckpoints: 2262.90ms -> 355.04ms p99
  • checkpointDiffQuery.getTurnDiff: 2937.21ms -> 191.04ms p99

Before

before.vcs.optimisation.mp4

AFTER

vsc.after.optimisations.mp4

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Replace legacy runProcess with a typed ProcessRunner service to speed up VCS diff loading

  • Replaces the Promise-based runProcess and Node child_process implementation in processRunner.ts with an Effect-based ProcessRunner DI service backed by stream-based stdin/stdout/stderr handling.
  • Introduces typed error classes (ProcessSpawnError, ProcessTimeoutError, ProcessOutputLimitError, etc.) replacing generic Error instances, enabling pattern-matched failure handling.
  • Renames truncateOutputAtMaxBytes to appendTruncationMarker across VcsProcess, GitVcsDriver, and GitVcsDriverCore; fixes a performance issue in collectUint8StreamText.ts by accumulating raw byte chunks and decoding once instead of incrementally.
  • Adds a checkpoints API to VcsDriverShape and implements captureCheckpoint, hasCheckpointRef, restoreCheckpoint, and diffCheckpoints in GitVcsDriver; CheckpointStore now delegates all checkpoint ops to the active VCS driver.
  • getFullThreadDiff in CheckpointDiffQuery now uses a dedicated getFullThreadDiffContext query (via ProjectionSnapshotQuery) instead of delegating to getTurnDiff, enabling a direct turn-0-to-target diff without preflight hasCheckpointRef checks.
  • Risk: VcsProcess, RepositoryIdentityResolver, ServerEnvironmentLabel, and TerminalManager layers now require ProcessRunner in their environment; callers providing these layers must include ProcessRunnerLive.

Macroscope summarized cc97acb.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 62c4fd45-3b79-4845-af36-1351b9a35c75

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels May 8, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 8, 2026

Approvability

Verdict: Needs human review

This PR refactors core infrastructure including process execution (converting to Effect-based patterns), checkpoint handling (moving operations into VCS driver layer), and adds new database query paths. The scope and architectural changes warrant human review despite the optimization framing.

You can customize Macroscope's approvability policy. Learn more.

Comment thread apps/server/src/capturedProcess.ts Outdated
Comment thread apps/server/src/stream/collectUint8StreamText.ts Outdated
Comment thread apps/server/src/processRunner.ts Outdated
Comment thread apps/server/src/vcs/GitVcsDriver.ts
Comment thread apps/server/src/checkpointing/Layers/CheckpointDiffQuery.ts Outdated
Comment thread apps/server/src/orchestration/Services/ProjectionSnapshotQuery.ts Outdated
Comment thread apps/server/src/project/Layers/RepositoryIdentityResolver.ts Outdated
Comment thread apps/server/src/terminal/Layers/Manager.test.ts Outdated
Comment thread apps/server/src/vcs/VcsProcess.test.ts
Comment thread apps/server/src/vcs/VcsProcess.ts Outdated
Comment thread apps/server/src/processRunner.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants