perf(editor): optimize code-lens entity lookup and cache popover fetches - #10416
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Light2Dark
marked this pull request as ready for review
July 31, 2026 11:33
Contributor
Coverage Report for ./frontend
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
No issues found across 8 files
Architecture diagram
sequenceDiagram
participant UI as Editor UI
participant Lens as Code Lens Extension
participant Entities as getLensEntities
participant Store as Jotai Store
participant Analyzer as findCacheSites
participant Popover as Cache Popover
participant API as getCacheInfo API
Note over UI,API: Code Lens Entity Lookup (per cell render)
UI->>Lens: Render code lenses for cell
Lens->>Entities: getLensEntities(cellId)
Entities->>Store: get(lensEntitiesByCellAtom)
Store->>Store: CHANGED: Precompute lensEntityKindsAtom (scans datasets, connections, storage)
Store->>Store: CHANGED: Group by declaring cell in lensEntitiesByCellAtom -> O(T) total
Store-->>Entities: { byCell, pending }
Entities-->>Lens: Map<string, CodeLensKind> (O(1) per-cell lookup)
Lens-->>UI: Render lens decorations
Note over UI,Analyzer: Cache Site Detection (syntax error fast-path)
UI->>Lens: Parse cell code for cache sites
Lens->>Analyzer: findCacheSites(state)
Analyzer->>Analyzer: Parse syntax tree
alt Syntax errors present
Analyzer->>Analyzer: CHANGED: Return empty array immediately
Analyzer-->>Lens: [] (no regex scan)
else Valid syntax
Analyzer->>Analyzer: Apply CACHE_PATTERN regex
Analyzer-->>Lens: CacheSite[]
end
Note over UI,API: Cache Popover Throttling (repeated hovers)
UI->>Popover: Hover over cache lens (mountLensPopover)
Popover->>Popover: Check hasLocalStats (per-cache boundName)
alt Has per-cache stats
Popover->>Popover: Show local hit/miss stats
else No per-cache stats
Popover->>Popover: CHANGED: Check lastCacheInfoFetchAt throttle
alt Within 5s throttle window
Popover->>Popover: Skip fetch (reuse cached data)
else Throttle expired or first fetch
Popover->>Popover: CHANGED: Set lastCacheInfoFetchAt = now
Popover->>API: getCacheInfo()
alt Success
API-->>Popover: Cache info data
Popover->>Popover: Display fallback stats
else Failure
API-->>Popover: Error
Popover->>Popover: CHANGED: Reset lastCacheInfoFetchAt = null (allow immediate retry)
end
end
end
Popover-->>UI: Render popover content
mscolnick
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #10161 that optimizes
editor_code_lenshot paths and adds regression coverage.getLensEntities: Precompute datasource/bucket entity kinds once per store update via Jotai derived atoms (lensEntityKindsAtom,lensEntitiesByCellAtom), turning per-cell O(C × T) rescans into O(T) grouping plus O(1) per-cell lookups.findCacheSites: Bail out early on syntax errors (same asfindDeclarationSites), avoiding regex scans on unparsable cells mid-edit.getCacheInfofetches across repeated hovers (5s interval); reset throttle on failure so the next hover can retry immediately.Tests
perf.test.ts— wall-time regression guards for large notebooks (generous 200ms budgets)entities.test.ts— shared entity map is built once, not pergetLensEntitiescallpopover.test.ts— fetch throttling and failure retry behavioranalyzer.test.ts— syntax-error short-circuit forfindCacheSitesTest plan
pnpm test src/core/codemirror/code-lensgetCacheInforequest fires within 5s