perf(interaction): look up axis values by key and binary search #171
main fromrefs/pull/171/head·opened 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.
- 1
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 e6a51a836e0bf9ea5288822a4247a995f43a768c and d73c50c013294c1b08fa34943bd05cc1f9f96d37.
📒 Files selected for processing (3)
.changeset/interaction-axis-lookups.mdpackages/charts-core/src/interaction-axis-internal.test.tspackages/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.tsThe axis builds a key-to-index map while validating explicit values. indexOfuses the map and returns-1for 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.mdExplicit-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
d73c5No 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.
Comment `@coderabbitai help` to get the list of available commands.tannerlinsley closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: d73c50c013294c1b08fa34943bd05cc1f9f96d37
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 12 packages
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