Public: anyone can read this; the crew can change it.

A pull's Files page reuses its rendered diff for the same head, and nothing viewer-specific is shared #4093

opened this

Merged 42d 15h ago, live in production

The Files page now keeps the diff and its syntax highlighting for each base and head pair, so a second view of the same head skips the git reads and the highlighting. The new test file and test/pull-timing.test.ts, test/pulls.test.ts and test/pull-render-budget.test.ts pass (16 tests), and bun x tsc --noEmit is clean.

Notes

opened this

The Files page now keeps the diff and its syntax highlighting for each base and head pair, so a second view of the same head skips the git reads and the highlighting. The new test file and test/pull-timing.test.ts, test/pulls.test.ts and test/pull-render-budget.test.ts pass (16 tests), and bun x tsc --noEmit is clean. I did not run the rest of the suite; the forge runs the full check on the push.

What is cached. src/web/diff-cache.ts is a new module that holds the parsed diff, the merge base and the syntax map. The key is base oid, head oid, whitespace and layout. The page has no whitespace or layout controls yet, so those two parts of the key are constants for now.

What is not cached. I cached the data the diff body is built from, not the finished HTML. The HTML carries review links, forms, threads and marks, which differ per viewer. renderDiff still runs on every request. Caching the markup itself would need a viewer-neutral render with the per-viewer parts spliced in afterwards, which is a bigger change to diff-view.ts.

Bounds and timing.

  • It lives in memory only and is bounded at 32 entries and about 32 MB estimated, with the least recently used entry dropped first.
  • Cached values are shared read-only.
  • Server-Timing on the Files page now has a diff phase, written as desc="hit" when it came from the cache.

Changes in src/web/pages/pull.ts. pullFilesPage now calls pullStatus, then the cache, instead of pullDiff plus diffSyntax. pullDiff itself is untouched.

Tests are in test/pull-files-cache.test.ts:

  • A second view of the same head reports a hit.
  • A new head renders fresh.
  • Three viewers (a guest, a reader and the writer) each get only their own forms. The guest page warms the cache first. The writer's form actions are a strict superset of the reader's, and the reader's of the guest's. No session token appears in another viewer's page.
  • The cache stops at its entry limit.
  • The key changes with the view options.

I did not rebase onto #4020 or check whether it has landed.

Closes #4086

commented

The Files page now keeps the diff and its syntax highlighting for each base and head pair, so a second view of the same head skips the git reads and the highlighting. The new test file and test/pull-timing.test.ts, test/pulls.test.ts and test/pull-render-budget.test.ts pass (16 tests), and bun x tsc --noEmit is clean. I did not run the rest of the suite; the forge runs the full check on the push.

What is cached. src/web/diff-cache.ts is a new module that holds the parsed diff, the merge base and the syntax map. The key is base oid, head oid, whitespace and layout. The page has no whitespace or layout controls yet, so those two parts of the key are constants for now.

What is not cached. I cached the data the diff body is built from, not the finished HTML. The HTML carries review links, forms, threads and marks, which differ per viewer. renderDiff still runs on every request. Caching the markup itself would need a viewer-neutral render with the per-viewer parts spliced in afterwards, which is a bigger change to diff-view.ts.

Bounds and timing.

  • It lives in memory only and is bounded at 32 entries and about 32 MB estimated, with the least recently used entry dropped first.
  • Cached values are shared read-only.
  • Server-Timing on the Files page now has a diff phase, written as desc="hit" when it came from the cache.

Changes in src/web/pages/pull.ts. pullFilesPage now calls pullStatus, then the cache, instead of pullDiff plus diffSyntax. pullDiff itself is untouched.

Tests are in test/pull-files-cache.test.ts:

  • A second view of the same head reports a hit.
  • A new head renders fresh.
  • Three viewers (a guest, a reader and the writer) each get only their own forms. The guest page warms the cache first. The writer's form actions are a strict superset of the reader's, and the reader's of the guest's. No session token appears in another viewer's page.
  • The cache stops at its entry limit.
  • The key changes with the view options.

I did not rebase onto #4020 or check whether it has landed.

commented

I've pushed both fixes to the branch. The new test file plus test/pull-timing.test.ts and test/pulls.test.ts pass (14 tests), and bun x tsc --noEmit is clean. I haven't run the rest of the suite; the forge runs it on the push.

  • Failed reads aren't kept. A new helper, diffBetween in src/core/pulls.ts, returns { from, diff, failed }. When diffRange fails, failed is true and the diff is empty. keptDiff serves a result flagged failed but never stores it, so the next request retries git.
  • One shared helper. pullDiff and the Files page's cached path both call diffBetween, so the merge-base, diffRange and fallback logic now exists once. I removed the copy from pull.ts.
  • Tests.
    • A failed result is built twice and never lands in the cache, with no entry and no hit.
    • diffBetween reports failed on an unknown oid.
    • The test file's convoluted alice type is simplified.
  • Not done. Concurrent misses on the same head still each do the work. Sharing an in-flight request is a separate change, and a duplicate miss costs only time because the cache keeps just one result.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs