Skip to content

perf: replace setTimeout drag with optimised RAF split engine#22

Open
SumitRajpal wants to merge 1 commit intosvar-widgets:mainfrom
SumitRajpal:feat/raf-split-engine
Open

perf: replace setTimeout drag with optimised RAF split engine#22
SumitRajpal wants to merge 1 commit intosvar-widgets:mainfrom
SumitRajpal:feat/raf-split-engine

Conversation

@SumitRajpal
Copy link

@SumitRajpal SumitRajpal commented Mar 22, 2026

Summary

Replaces the original setTimeout(100ms) drag implementation with a fully
optimised RAF-based split engine, delivering significantly smoother resizing
across all devices.

What changed

New files

  • src/components/splitEngine/useDragEngine.js — standalone drag engine hook
  • src/components/splitEngine/clamp.js — pure arithmetic utility

Modified

  • src/components/Resizer.jsx — wired to new engine, DEV-only FPS overlay
  • src/components/Layout.jsx — passes layoutRef as containerRef to Resizer

Optimisations applied

# Optimisation Impact
1 CSS variable bypass onMove → React reconcile drops from 60/sec to 1 (on drop only). DOM writes go direct to GPU thread.
2 Stable V8 hidden class drag object never set to null — V8 holds one IC forever, no deopt.
3 setPointerCapture Browser skips hit-testing on every pointermove at 60fps.
4 getCoalescedEvents() No sub-frame pointer input silently discarded between RAF frames.
5 Closure-free hot path All values live in engineRef. handleMove has zero deps and is never re-JIT'd by V8.

DEV-only FPS overlay

A fixed bottom-right FPS counter is shown during active drag in development
mode only (import.meta.env.DEV). Stripped completely from production builds.

Test plan

  • Drag the resizer left and right — confirm smooth movement
  • Drag past left/right thresholds — confirm display switches to chart/grid
  • Release drag — confirm grid snaps to correct final position
  • Collapse/expand buttons still work in both compact and normal mode
  • FPS overlay appears bottom-right in dev, absent in prod build
  • Touch/stylus drag works (pointer events)

@SumitRajpal SumitRajpal force-pushed the feat/raf-split-engine branch from a911c3e to 716cc09 Compare March 22, 2026 11:01
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