Skip to content

perf(interaction): look up axis values by key and binary search - #171

Open
andersk wants to merge 1 commit into
TanStack:mainfrom
andersk:interaction-axis-lookups
Open

andersk wants to merge 1 commit into
TanStack:mainfrom
andersk:interaction-axis-lookups

Conversation

@andersk

@andersk andersk commented Oct 7, 2026 •

Copy link
Copy Markdown

Scale-bound interactions with explicit values scanned every value on each pointer event: indexOf searched the array of value keys, and valueAt measured the distance to every position. A brushX over 120,000 hourly values spent about 12 ms per mouse move in these scans, enough to make dragging stutter.

Record each value's index in the map that already checks values for uniqueness, and find the nearest position by binary search, which assertMonotonePositions already makes valid. Ties still resolve to the lower index, as with the linear search.

Summary by CodeRabbit

  • Performance
    • Improved pointer snapping and value lookups for charts with many explicitly defined values, including brush, zoom, handle, and cursor interactions.
    • Preserved consistent snapping behavior for forward and reversed axes, including when a pointer falls equally between two values.

Scale-bound interactions with explicit values scanned every value
on each pointer event: `indexOf` searched the array of value keys,
and `valueAt` measured the distance to every position. A brushX over
120,000 hourly values spent about 12 ms per mouse move in these
scans, enough to make dragging stutter.

Record each value's index in the map that already checks values for
uniqueness, and find the nearest position by binary search, which
`assertMonotonePositions` already makes valid. Ties still resolve to
the lower index, as with the linear search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d73c50c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/charts Patch
@tanstack/alpine-charts Patch
@tanstack/angular-charts Patch
@tanstack/lit-charts Patch
@tanstack/octane-charts Patch
@tanstack/preact-charts Patch
@tanstack/react-charts Patch
@tanstack/react-native-charts Patch
@tanstack/solid-charts Patch
@tanstack/svelte-charts Patch
@tanstack/vue-charts Patch
@tanstack/charts-scales Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0b32c5e7-540b-4d76-8996-b62e984935d1
📥 Commits

Reviewing files that changed from the base of the PR and between e6a51a8 and d73c50c.

📒 Files selected for processing (3)
  • .changeset/interaction-axis-lookups.md
  • packages/charts-core/src/interaction-axis-internal.test.ts
  • packages/charts-core/src/interaction-axis-internal.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The interaction axis now maps explicit values to indexes and uses binary search to select the nearest mapped position. Tests cover forward and reversed mappings, ties, and present or absent values.

Changes

Interaction axis lookups

Layer / File(s) Summary
Explicit-value index
packages/charts-core/src/interaction-axis-internal.ts
The axis builds a key-to-index map while validating explicit values. indexOf uses the map and returns -1 for absent values.
Nearest-position search
packages/charts-core/src/interaction-axis-internal.ts, packages/charts-core/src/interaction-axis-internal.test.ts, .changeset/interaction-axis-lookups.md
Explicit-value snapping uses binary search for ascending and descending positions. Tests cover nearest-value selection, endpoint clamping, ties, and indexOf. The changeset records a patch for @tanstack/charts.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to d73c5

No issue requiring a fix before merge is identified for the interaction-axis lookup change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: faster interaction-axis lookups by key and binary search.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

1 participant