Skip to content

perf(editor): optimize code-lens entity lookup and cache popover fetches - #10416

Merged
Light2Dark merged 3 commits into
ms/feature/editor-code-buttonsfrom
sham/perf-tests
Jul 31, 2026
Merged

perf(editor): optimize code-lens entity lookup and cache popover fetches#10416
Light2Dark merged 3 commits into
ms/feature/editor-code-buttonsfrom
sham/perf-tests

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #10161 that optimizes editor_code_lens hot 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 as findDeclarationSites), avoiding regex scans on unparsable cells mid-edit.
  • Cache popover: Throttle notebook-wide getCacheInfo fetches 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 per getLensEntities call
  • popover.test.ts — fetch throttling and failure retry behavior
  • analyzer.test.ts — syntax-error short-circuit for findCacheSites

Test plan

  • pnpm test src/core/codemirror/code-lens
  • Manual: hover a cache code lens repeatedly and confirm only one getCacheInfo request fires within 5s
  • Manual: open a large notebook with many datasources and confirm code lenses still feel responsive

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Jul 31, 2026 11:45am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Light2Dark Light2Dark changed the title add perf tests, and improve optimization perf(editor): optimize code-lens entity lookup and cache popover fetches Jul 31, 2026
@Light2Dark Light2Dark added the enhancement New feature or request label Jul 31, 2026
@Light2Dark
Light2Dark marked this pull request as ready for review July 31, 2026 11:33
@Light2Dark
Light2Dark requested a review from mscolnick July 31, 2026 11:33
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 77.37% 78924 / 102001
🔵 Statements 77.37% 78924 / 102001
🔵 Functions 72.02% 672 / 933
🔵 Branches 79.06% 4687 / 5928
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/core/codemirror/code-lens/analyzer.ts 100% 80% 100% 100%
frontend/src/core/codemirror/code-lens/entities.ts 100% 100% 100% 100%
frontend/src/core/codemirror/code-lens/popover.tsx 78.88% 29.41% 100% 78.88% 55, 57, 59, 68, 175, 196-213, 216-232
Generated in workflow #20144 for commit 3ed5e4f by the Vitest Coverage Report Action

@cubic-dev-ai cubic-dev-ai Bot 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.

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
Loading

Re-trigger cubic

@Light2Dark
Light2Dark merged commit 0ebcfef into ms/feature/editor-code-buttons Jul 31, 2026
39 checks passed
@Light2Dark
Light2Dark deleted the sham/perf-tests branch July 31, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants