Skip to content

perf(server): code snapshots stop re-reading uncommitted files - #1045

Merged
badcuban merged 1 commit into
mainfrom
perf/faster-code-snapshots
Nov 23, 2026
Merged

badcuban merged 1 commit into
mainfrom
perf/faster-code-snapshots

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Before each message reaches the agent, Threadlines saves a git snapshot of the checkout. PostHog shows 12% of messages waiting over 5 s on it, nearly all on Windows and Linux. Many stop at git's 30 s timeout, after which no snapshot is saved at all. Every snapshot re-read and re-hashed every file that was never committed, because loading the tree over the cached index (read-tree -m -i) drops those entries.

A checkpoint now stages over the cached index as it is. A cached entry is kept only when a cold build (read-tree <tree> + add -A) would stage it the same way:

  • a tree path when its mode and object match the tree's (as read-tree -m keeps it), since git reads a changed file's index blob for line endings and keeps modes and submodule commits under some settings;
  • any other file when it is listed under the same name, went in as a new file (the cache's file name now records the tree it was staged over), is not a link, and none of its folders has another spelling.

Everything else is dropped and read again, so the snapshot tree matches a cold build. Kept files that an ignore rule added mid-capture now covers are dropped after staging. A failed write after a warm start retries cold. Non-UTF-8 paths take the cold path.

The untracked listing runs against an index loaded from the tree instead of no index, so git no longer checks every committed file against the ignore rules.

Turn latency telemetry also reports whether the snapshot failed to save (docs/telemetry.md updated).

Measured on a Windows PC, 100k tracked files plus 3,000 new 50 KB files: git add 2,255 -> 141 ms, listing 1,635 -> 825 ms, same tree id.

Not covered: the first snapshot in a new worktree is still cold (9.5 s at 100k files on that PC). Starting it from the worktree's own index was tried and dropped after review: that index can hold blobs from older conversion rules, staged mode or case changes, and assume-unchanged entries.

Before each message reaches the agent, Threadlines saves a git snapshot
of the checkout. PostHog shows 12% of messages waiting over 5 s on it
(nearly all Windows and Linux), and many hitting git's 30 s timeout,
after which no snapshot is saved at all.

Each snapshot loaded the tree over the cached scratch index with
`read-tree -m -i`, which drops every entry the tree lacks, so `git add
-A` read and hashed every never-committed file again. A checkpoint now
stages over the cache as it is (`stageCheckout`). A cached entry stays
only when a cold build would stage it the same way: a tree path when it
is the tree's entry, any other file when it is listed under the same
name, went in as new (the cache's name records the tree it was staged
over), is not a link, and is not under another spelling of a folder.
Everything else is read again, so the tree matches a cold build. A
failed write after a warm start retries cold.

The untracked listing now runs against an index loaded from the tree
instead of no index, so git no longer checks every committed file
against the ignore rules.

Measured on a Windows PC, 100k tracked files plus 3,000 new 50 KB
files: `git add` 2,255 -> 141 ms, the listing 1,635 -> 825 ms, same tree.

Turn latency telemetry also says whether the snapshot failed to save.
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 23, 2026 9:26am UTC

Request Review

@badcuban
badcuban added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit ce5476b Nov 23, 2026
23 checks passed
@badcuban
badcuban deleted the perf/faster-code-snapshots branch November 23, 2026 09:38

This branch was previously deployed

1 inactive deployment
Preview — 758ec627 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant