Skip to content

perf(decofile): make in-commit blocks.gen.json regen cache-aware - #6707

Open
guitavano wants to merge 1 commit into
mainfrom
guitavano/decofile-patch-slow
Open

perf(decofile): make in-commit blocks.gen.json regen cache-aware#6707
guitavano wants to merge 1 commit into
mainfrom
guitavano/decofile-patch-slow

Conversation

@guitavano

@guitavano guitavano commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

The decofile commit path (commit-coalescer.ts) regenerates a committed .deco/blocks.gen.json inside every save commit. Today it re-fetches every unchanged block via client.getBlobText (bypassing the disk cache) in an unbounded Promise.all. On a large repo (e.g. Granado, ~325 blocks) that's hundreds of uncached GitHub round-trips per save — several seconds of latency before the preview can even load, since the preview reads by commit sha.

This is the general-case (option "a") counterpart to per-repo untracking of the artifact: it helps every repo that keeps blocks.gen.json committed.

Change

Align the in-commit regen with the read path (resolveSnapshot):

  1. Read unchanged blocks disk-cache-first + bounded. New shared getBlockText(client, sha) tries the disk cache before GitHub and writes through on a miss; the loop uses mapBounded(..., BLOB_FETCH_CONCURRENCY). The editor's read right before a save already primed those blobs, so a same-replica save is mostly cache hits; a cold replica fetches at most N at a time instead of stampeding GitHub's abuse limiter (the exact reason the read path is already bounded).
  2. Prime the merged-doc cache after commit. primeMergedSnapshot(...) stores the just-computed document under the new sha's merged-doc key — byte-identical to what resolveSnapshot produces at that sha (same mergeBlocks, same sort) — so the preview read immediately after a save is a disk hit instead of a fresh tree read + re-merge.

Scope / tradeoff

  • Only repos that commit blocks.gen.json enter the regen branch; gitignored repos (the common case) are untouched.
  • Known tradeoff (option "a"): the big win is on the warm path (same replica, not yet LRU-evicted). A cold replica still fetches all blocks — but now bounded instead of an unbounded stampede, so it's never worse than before. The deterministic-but-riskier alternative (incremental patch of the prev gen) would break byte-identity with the daemon's canonical merge, so it was not taken here.

Testing

  • New e2e (decofile-api.spec.ts): seeds a repo with a stale committed blocks.gen.json (missing a block, pre-edit value), PATCHes a block, and asserts the artifact was fully re-merged (edited + untouched blocks, keys sorted by filename). This branch had zero e2e coverage before. Passing locally against the real server + GitHub stub (1 passed (15.4s)).
  • bun run check (apps/api + packages/e2e) and existing decofile unit tests pass; bun run fmt clean.

🤖 Generated with Claude Code


Summary by cubic

Speeds up saves in repos that commit .deco/blocks.gen.json by making the in-commit regeneration disk-cache-first and bounded, instead of re-fetching every unchanged block from GitHub in an unbounded Promise.all.

  • Reads unchanged blocks through the shared getBlockText path with BLOB_FETCH_CONCURRENCY concurrency, mirroring the read path.
  • Primes the merged-doc cache for the new commit sha so the preview read right after a save hits disk instead of re-reading the tree and re-merging.
  • Only affects repos that commit the artifact; gitignored repos are untouched.
  • Adds an e2e test covering the regeneration branch, which previously had no coverage.

Written for commit f92ea96. Summary will update on new commits.

Review in cubic

The decofile commit path regenerates a committed .deco/blocks.gen.json
inside every save commit. It fetched every unchanged block via
client.getBlobText (no disk cache) in an unbounded Promise.all — on a
large repo (e.g. ~325 blocks) that is hundreds of uncached GitHub round
trips per save, adding several seconds of latency before the preview can
load.

Align the regen with the read path (resolveSnapshot):
- Read unchanged blocks disk-cache-first via a shared getBlockText, with
  bounded concurrency (BLOB_FETCH_CONCURRENCY). The editor's read just
  primed those blobs, so a same-replica save is mostly cache hits; a cold
  replica fetches at most N at a time instead of stampeding GitHub's abuse
  limiter.
- After the commit lands, prime the merged-doc cache (primeMergedSnapshot)
  with the just-computed document — byte-identical to what resolveSnapshot
  produces at that sha — so the preview read immediately after a save is a
  disk hit rather than a fresh tree read + re-merge.

Only affects repos that commit blocks.gen.json; gitignored repos (the
common case) never enter the regen branch and are unchanged.

Adds an e2e test asserting the regen replaces a stale committed artifact
with a full re-merge of the block set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant