Skip to content

[diffs] Cache serialized file header HTML on recycled File and FileDiff instances#715

Merged
amadeus merged 1 commit into
beta-1.2from
autoresearch/diffshub-header-cache/01-header-html-cache
May 20, 2026
Merged

[diffs] Cache serialized file header HTML on recycled File and FileDiff instances#715
amadeus merged 1 commit into
beta-1.2from
autoresearch/diffshub-header-cache/01-header-html-cache

Conversation

@SlexAxton

Copy link
Copy Markdown
Contributor

Summary

This PR caches serialized file header HTML on recycled File and FileDiff instances.

Diffshub’s large-jump profile showed repeated work in applyHeaderToDOM, especially converting stable header HAST back into HTML during virtualized recycle. The rendered DOM is still rebuilt as before, but stable header HTML no longer pays repeated toHtml(headerAST) serialization cost while the same virtualized instance is reused for the same file or diff.

What changed

  • Added cachedHeaderHTML to:

    • packages/diffs/src/components/File.ts
    • packages/diffs/src/components/FileDiff.ts
  • Updated applyHeaderToDOM to reuse cached serialized header HTML:

      const headerHTML = this.cachedHeaderHTML ?? toHtml(headerAST);
      this.cachedHeaderHTML = headerHTML;
  • Preserved the cache across virtualized recycle cleanup:

      if (!recycle) {
        this.cachedHeaderHTML = undefined;
      }
  • Invalidated the cache when header output may change:

    • setOptions(...)
    • file identity/content changes in File
    • diff identity/content changes in FileDiff
    • non-recycle cleanup

Why

During CodeView jumps, virtualized items are cleaned up and remounted often. The header content for a given file/diff is
usually stable, but the old code serialized its header AST every time applyHeaderToDOM ran.

This keeps the visual and DOM behavior the same while avoiding repeated HAST-to-HTML conversion for stable headers.

Performance

Autoresearch profile:

  actionDurationMs: 1415ms → 1345.2ms (-4.9%)

Workload:

  bun run diffshub:profile -- --action jump --json

This benchmark jumps between sections of a large diff outside the current virtual window, so each target requires fresh
rendered code.

Correctness notes

This caches only the serialized header string, not DOM nodes. Header DOM is still created, replaced, and mounted through
the existing path.

The cache is cleared when options or file/diff identity changes, so custom header modes, metadata changes through new
file/diff objects, and non-recycle cleanup continue to render fresh header HTML.

Validation

The finalized branch was created with the autoresearch finalizer, which ran the repo’s precommit checks while committing:

  • tsgo --noEmit --pretty
  • oxfmt --write
  • oxlint --type-aware --tsconfig tsconfig.oxlint.json --fix

The finalizer also verified that the review branch contains no autoresearch session artifacts.

@vercel

vercel Bot commented May 19, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
pierre-docs-diffshub Ready Ready Preview May 19, 2026 10:59pm
pierre-docs-trees Ready Ready Preview May 19, 2026 10:59pm
pierrejs-diff-demo Ready Ready Preview May 19, 2026 10:59pm
pierrejs-docs Ready Ready Preview May 19, 2026 10:59pm

Request Review

Preserve serialized file header HTML while a virtualized File/FileDiff instance is recycled, and invalidate it when options or file/diff identity change. This avoids repeating HAST-to-HTML serialization for stable headers during large CodeView jumps.

Experiments: #13
Metric: actionDurationMs 1415ms → 1345.2ms (-4.9%)

@amadeus amadeus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tang u 4️⃣ ur service

@amadeus
amadeus merged commit 9e4765e into beta-1.2 May 20, 2026
12 checks passed
@amadeus
amadeus deleted the autoresearch/diffshub-header-cache/01-header-html-cache branch May 20, 2026 05:27
amadeus pushed a commit that referenced this pull request May 20, 2026
…ff instances (#715)

Cache File and FileDiff header HTML across recycle

Preserve serialized file header HTML while a virtualized File/FileDiff instance is recycled, and invalidate it when options or file/diff identity change. This avoids repeating HAST-to-HTML serialization for stable headers during large CodeView jumps.

Experiments: #13
Metric: actionDurationMs 1415ms → 1345.2ms (-4.9%)
amadeus pushed a commit that referenced this pull request May 20, 2026
…ff instances (#715)

Cache File and FileDiff header HTML across recycle

Preserve serialized file header HTML while a virtualized File/FileDiff instance is recycled, and invalidate it when options or file/diff identity change. This avoids repeating HAST-to-HTML serialization for stable headers during large CodeView jumps.

Experiments: #13
Metric: actionDurationMs 1415ms → 1345.2ms (-4.9%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants