Skip to content

perf: throttle brush drag commits#30

Closed
dougasimpson wants to merge 1 commit into
legions-developer:mainfrom
dougasimpson:perf/brush-drag-raf
Closed

perf: throttle brush drag commits#30
dougasimpson wants to merge 1 commit into
legions-developer:mainfrom
dougasimpson:perf/brush-drag-raf

Conversation

@dougasimpson
Copy link
Copy Markdown

Summary

  • cache the brush container width at pointer-down instead of reading layout on every pointer move
  • batch drag commits with requestAnimationFrame and commit only the latest pending range per frame
  • flush the final pending range on pointer-up so the selected range remains exact
  • cancel pending animation frames on unmount
  • use the pointer event target for pointer capture and release

Benefits

This reduces forced layout reads during drag and prevents React state updates from running faster than the browser can paint. In dense dashboards that update chart data while the brush is moving, this keeps the brush interaction closer to frame cadence and reduces visible jitter.

Notes

  • No public API changes
  • Controlled-mode sync remains unchanged
  • The final brush range is still committed exactly on pointer-up

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 21, 2026

@dougasimpson is attempting to deploy a commit to the Invoicely OSS Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a742bc4-768a-4fcb-931e-ec5377e9898f

📥 Commits

Reviewing files that changed from the base of the PR and between 50055d8 and a30b471.

📒 Files selected for processing (1)
  • src/registry/ui/evil-brush.tsx

📝 Walkthrough

Walkthrough

The useBrushDrag hook in evil-brush.tsx is refactored to defer pointer-driven range commits via requestAnimationFrame. The drag state now caches container width, and a new scheduleCommit mechanism batches updates instead of applying them synchronously on every move, reducing layout thrashing. Pointer capture/release is updated to use currentTarget, and cleanup properly cancels any pending RAF on pointer up and unmount.

Changes

Brush Drag RAF Batching

Layer / File(s) Summary
Drag state shape and RAF batching infrastructure
src/registry/ui/evil-brush.tsx
DragState now includes a cached width field. New refs and scheduleCommit function establish RAF-batching for deferred range updates, with a deltaToIndex helper that consumes the cached width.
Pointer event handler refactoring
src/registry/ui/evil-brush.tsx
Pointer down captures on currentTarget and stores container width. Pointer move computes deltas using cached width and enqueues scheduled commits. Center dragging adopts the same scheduled commit pattern.
Pointer up and unmount cleanup
src/registry/ui/evil-brush.tsx
Pointer up releases capture, cancels pending RAF, applies final queued commit, and resets refs. An unmount effect ensures any remaining RAF is cancelled.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main performance optimization: throttling brush drag commits using requestAnimationFrame to reduce layout thrashing.
Description check ✅ Passed The description is directly related to the changeset, providing clear details about the implementation approach, benefits, and notes about backward compatibility.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@legions-developer
Copy link
Copy Markdown
Owner

can you verify commit?

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