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

A pull's Files page answers a 40-file diff in under 100 ms on a repeat view #4045

Parked opened this
Closed without merging

A repeat view of a 40-file Files page now takes about 55 ms, down from the 130–200 ms in the issue. The new tests pass, along with the 69 existing diff and pull tests. I couldn't run the type check: bun x tsc --noEmit failed here with "unable to write files to tempdir", so the forge's check will be its first run.

Notes

stopped parked by the crew deploy f525280

opened this

A repeat view of a 40-file Files page now takes about 55 ms, down from the 130–200 ms in the issue. The new tests pass, along with the 69 existing diff and pull tests. I couldn't run the type check: bun x tsc --noEmit failed here with "unable to write files to tempdir", so the forge's check will be its first run.

What changed

  • New src/web/diff-cache.ts: a small least-recently-used map, with two bounded caches built on it. One holds highlighted tokens per head (32 entries) and the other holds rendered file HTML (512 entries).
  • pullFilesPage in src/web/pages/pull.ts keeps the highlighting under a key of repo directory, merge base and head oid. A moved head finds nothing of the old one.
  • renderDiff in src/web/diff-view.ts keeps each file's rendered HTML, but only for files with no review comment and no open comment form.
  • Threads, marks and comment forms are never cached. The review and file links are part of the key, so a signed-in and a signed-out viewer get different entries.
  • test/pull-files-cache.test.ts seeds a 40-file diff and checks three things:
    • The median of five repeat views is under 100 ms, and the cold view is under 800 ms.
    • After the head moves, the page shows none of the old head's HTML.
    • A signed-out view has no ?rc= review links, and two different signed-in viewers each get them.

Left out

  • The ceilings in test/pull-timing.test.ts are not tightened. That file has no 1000 ms / 400 ms assertions on this branch. The only timing assertion I added is the one in the new test.
  • pullDiff still runs the status, merge-base and git diff calls on every view. That is a small part of the repeat cost, so I left it uncached.
  • A file with a review comment is redrawn on every view.

Try it Run bun test test/pull-files-cache.test.ts. It prints the cold and repeat timings.

Closes #4043

commented

A repeat view of a 40-file Files page now takes about 55 ms, down from the 130–200 ms in the issue. The new tests pass, along with the 69 existing diff and pull tests. I couldn't run the type check: bun x tsc --noEmit failed here with "unable to write files to tempdir", so the forge's check will be its first run.

What changed

  • New src/web/diff-cache.ts: a small least-recently-used map, with two bounded caches built on it. One holds highlighted tokens per head (32 entries) and the other holds rendered file HTML (512 entries).
  • pullFilesPage in src/web/pages/pull.ts keeps the highlighting under a key of repo directory, merge base and head oid. A moved head finds nothing of the old one.
  • renderDiff in src/web/diff-view.ts keeps each file's rendered HTML, but only for files with no review comment and no open comment form.
  • Threads, marks and comment forms are never cached. The review and file links are part of the key, so a signed-in and a signed-out viewer get different entries.
  • test/pull-files-cache.test.ts seeds a 40-file diff and checks three things:
    • The median of five repeat views is under 100 ms, and the cold view is under 800 ms.
    • After the head moves, the page shows none of the old head's HTML.
    • A signed-out view has no ?rc= review links, and two different signed-in viewers each get them.

Left out

  • The ceilings in test/pull-timing.test.ts are not tightened. That file has no 1000 ms / 400 ms assertions on this branch. The only timing assertion I added is the one in the new test.
  • pullDiff still runs the status, merge-base and git diff calls on every view. That is a small part of the repeat cost, so I left it uncached.
  • A file with a review comment is redrawn on every view.

Try it Run bun test test/pull-files-cache.test.ts. It prints the cold and repeat timings.

commented

Parked by the crew: the check failed and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs