Skip to content

perf: reuse assembled Copilot notebook documents - #12267

Merged
kirangadhave merged 1 commit into
mainfrom
kg/bench-copilot-doc-sync
Dec 3, 2026
Merged

kirangadhave merged 1 commit into
mainfrom
kg/bench-copilot-doc-sync

Conversation

@kirangadhave

@kirangadhave kirangadhave commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

📝 Summary

Reuse the assembled notebook text when GitHub Copilot requests another inline completion with unchanged code. When the focused cell changes, reuse the prefix if the other cells still contribute the same text in the same order. Read mounted editors directly so edits are visible before the notebook store updates. Release the cache when the last editor closes.

Copilot still sends full-text updates and flushes the latest pending edit before a suggestion. The cache preserves the existing order for numeric cell IDs. A regression test checks the document text and completion version after a cell move.

Related work in MO-8797

Verification

All 155 Copilot tests passed. The benchmark used a 320-cell notebook, the enabled Copilot editor, and an in-process language server. Each timing is the median for a batch of 48 requests across six alternating pairs.

Workload Full builds before Full builds after Flush time before Flush time after
Unchanged code after the first flush 48 0 4.04 ms 0.91 ms
Upstream edit before every request 48 48 35.67 ms 35.70 ms

In a mixed editing workload, full builds fell from 33 to 8, plus 7 prefix builds. Both clients produced the same document text, versions, and cursor positions for all 32 requests. Both sent 3,696,062 bytes of serialized document notifications. With the 150 ms debounce, the three median edit-to-display times were 0.28 to 0.60 ms higher with the cache. The benchmark excludes network latency, provider latency, and browser paint.

@kirangadhave
kirangadhave marked this pull request as ready for review December 3, 2026 19:07
@kirangadhave
kirangadhave requested review from mscolnick and a balanced review from Copilot December 3, 2026 19:07
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 8351bb1.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the notebook-text caching and document lifecycle changes.

No open issues 🎉

What changed in this PR

Reduces repeated notebook-text assembly for GitHub Copilot completions while preserving full-text updates and document ordering.

Changes:

  • Caches assembled documents and reuses unchanged cell prefixes.
  • Reads mounted editors for current text and releases cached state when the last editor closes.
  • Adds coverage for cache reuse, cell ordering, completion versions, and cleanup.
File Description
frontend/​src/​core/​codemirror/​copilot/​language-server.ts Integrates caching and document lifecycle cleanup.
frontend/​src/​core/​codemirror/​copilot/​getCodes.ts Extracts shared import-first sorting.
frontend/​src/​core/​codemirror/​copilot/​document.ts Implements cached notebook-text assembly.
frontend/​src/​core/​codemirror/​copilot/​__tests__/​language-server.test.ts Covers versions, ordering, reconnects, and cleanup.
frontend/​src/​core/​codemirror/​copilot/​__tests__/​document.test.ts Tests prefix reuse and cell changes.
frontend/​src/​core/​codemirror/​copilot/​__tests__/​completion-integration.test.ts Tests completion behavior with mounted notebook editors.

Review effort: Balanced

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.77% 28995 / 41555
🔵 Statements 69.73% 29567 / 42400
🔵 Functions 65.28% 7004 / 10729
🔵 Branches 65.24% 17015 / 26079
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/core/codemirror/copilot/document.ts 100% 92.85% 100% 100%
frontend/src/core/codemirror/copilot/getCodes.ts 98.21% 71.42% 100% 98.11% 99
frontend/src/core/codemirror/copilot/language-server.ts 74.84% 82.85% 75.86% 74.69% 138, 222, 237, 250, 257, 270-277, 282-285, 288-291, 368-409, 490, 513-528
Generated in workflow #26544 for commit 8351bb1 by the Vitest Coverage Report Action

@kirangadhave
kirangadhave merged commit da858bb into main Dec 3, 2026
31 of 32 checks passed
@kirangadhave
kirangadhave deleted the kg/bench-copilot-doc-sync branch December 3, 2026 19:26
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.

3 participants