Skip to content

perf(s2): look up hover fractions with an indexed expression function - #991

Merged
c-lamoureux merged 6 commits into
mainfrom
perf/s2-hover-fraction-fn
Oct 9, 2026
Merged

c-lamoureux merged 6 commits into
mainfrom
perf/s2-hover-fraction-fn

Conversation

@c-lamoureux

Copy link
Copy Markdown
Contributor

Stacked on #990.

What

  • New hoverFraction(rows, keyField, key, fallback) expression function. It indexes hoverFractionData rows by key once per data array (a WeakMap cache) and reads each row's value live.
  • Line, bar and legend hover opacity use it instead of indexof(pluck(data(...))), which scanned every series for every item on every frame.
  • Storybook S2: turns off Storybook 10's built-in highlight feature (features.highlight: false). It runs querySelectorAll('*') + getComputedStyle on every DOM change in the story, which skewed hover benchmarks.
  • The line hover dashboard perf story gets a renderer (svg/canvas) arg.

Why

With the CSP-safe interpreter, the pluck/indexof lookup was O(series) per item per frame. The lookup is now O(1) after one index build per data change.

Perf

  • Interpreted nodes per lookup: 25 → 19; the per-frame pluck is gone.
  • 20-chart line hover dashboard, 4× CPU, 5 runs: 18.5 → 20.0 median chart fps (within noise; a modest gain).

Testing

  • Unit tests for hoverFraction (match, fallback, first row wins, live reads).
  • A real Vega test (CSP interpreter, ast: true) that applies modify/insert changesets and checks the lookup stays current. It fails if the function caches values instead of rows.
  • vega-interpreter added as a devDependency for that test only; no runtime dependency change.
  • S1 has no hover-fraction code, so no S1 change.

@c-lamoureux
c-lamoureux force-pushed the perf/s2-line-clip-draw-in branch from f0bd757 to ac9e5b3 Compare October 9, 2026 18:01
@c-lamoureux
c-lamoureux force-pushed the perf/s2-hover-fraction-fn branch 3 times, most recently from 54afac5 to 9ed939b Compare October 9, 2026 18:27
Base automatically changed from perf/s2-line-clip-draw-in to main October 9, 2026 20:41
c-lamoureux and others added 3 commits October 9, 2026 14:43
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…r perf story

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@c-lamoureux
c-lamoureux force-pushed the perf/s2-hover-fraction-fn branch from 9ed939b to ce3c0ae Compare October 9, 2026 20:43
@c-lamoureux
c-lamoureux marked this pull request as ready for review October 9, 2026 20:50
c-lamoureux and others added 3 commits October 9, 2026 14:58
…ype-aware redundant optionals

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…er arg

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@c-lamoureux
c-lamoureux merged commit 2df92a3 into main Oct 9, 2026
7 checks passed
@c-lamoureux
c-lamoureux deleted the perf/s2-hover-fraction-fn branch October 9, 2026 22:05
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