Skip to content

perf(pointer): cache element bounds for pointer interactions - #46

Merged
DavidHDev merged 1 commit into
DavidHDev:mainfrom
phh235:perf/cache-pointer-rect
Aug 18, 2026
Merged

perf(pointer): cache element bounds for pointer interactions#46
DavidHDev merged 1 commit into
DavidHDev:mainfrom
phh235:perf/cache-pointer-rect

Conversation

@phh235

@phh235 phh235 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR improves pointer interaction performance across the Vanilla implementations used by the Vue, Solid, and Svelte components.

getBoundingClientRect() was being called inside 20 high-frequency pointermove handlers. The element bounds are now cached and refreshed only when the layout can change, such as during resize or scroll. The cache and its event listeners are also cleaned up when the component is destroyed.

This change reduces unnecessary main-thread work during pointer movement and makes interactive effects more responsive, especially on lower-end devices or when multiple effects are active.

Benchmark

Chromium headless benchmark across 20 pointer handlers and 4,000,000 total iterations:

Metric Before After Improvement
Processing time 129.3 ms 11.6 ms 117.7 ms less
Relative speed 11.1× 91.0% faster

Type of change

  • Component improvement

Checklist

  • npx tsc --noEmit passes
  • npm run lint passes
  • npm run build passes
  • Tested in Chrome (with the html-in-canvas flag, if relevant)
  • Tested the WebGL overlay fallback (flag off / Safari / Firefox), if a component changed

Avoid repeated getBoundingClientRect calls in pointermove handlers by caching element bounds and refreshing them on layout changes.
@DavidHDev
DavidHDev merged commit ef770dd into DavidHDev:main Aug 18, 2026
1 check passed
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