perf: batch panel resize reads/writes, debounce mastery-slider prefs saves - #31
Conversation
sizeCanvases() (and the two window-resize handlers that mirror its loop
shape) called getBoundingClientRect()/offsetHeight for panel N right
after panel N-1's canvas-size writes, forcing a synchronous layout
recalc on every iteration — worst on tri/quad/five/six layouts. hw.resize
now accepts an optional precomputed {rect, barH} so callers that resize
several panels in one pass can measure everything first, then apply all
the writes, costing one layout flush instead of one per panel.
The mastery slider's oninput handler also called savePanelPrefs()
(JSON.stringify + localStorage.setItem over every panel) on every
`input` tick while dragging. It now goes through a new
savePanelPrefsDebounced(), coalescing rapid drags into a single write
~300ms after the last change. Any direct savePanelPrefs() call (e.g.
stopSplitScreen's teardown) still cancels a pending debounced write, so
a stale timer can't fire after `panels` has been reset to [].
Bump plugin.json to 1.14.3 (patch) per this repo's versioning
convention.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — this review covers commit 1eb1096 against main.
- Layout-thrashing elimination in
sizeCanvases()— the main-window resize path now batches every panel'sgetBoundingClientRect()/offsetHeightreads into ameasuredarray before any canvas-size writes, collapsing N forced layout flushes into one.hw.resize()accepts an optional precomputed{rect, barH}and falls back to self-measuring for single-panel callers. - Same batching in follower window resize handler — the
buildFollowerLayoutresize listener mirrors the pattern for multi-panel popups. - Debounced mastery-slider prefs save —
savePanelPrefsDebounced()(300 ms coalescing) replaces the per-ticksavePanelPrefs()in the slider'soninput.savePanelPrefs()itself clears any pending debounce timer, so teardown-time saves and every other direct call site still flush immediately without risk of a stale write clobbering state. - Plugin version bump —
1.14.2→1.14.3patch.
Big Pickle (free) | 𝕏

Summary
Two verified performance fixes, no behavior change:
sizeCanvases()and the two window-resize handlers that mirror its shape looped over panels doing agetBoundingClientRect()/offsetHeightread immediately followed by canvasstyle/width/heightwrites, then read again for the next panel — forcing a synchronous layout recalc every iteration (worst on tri/quad/five/six layouts, up to 6 panels).hw.resize()now takes an optional precomputed{rect, barH}, and the resize call sites measure every panel first, then apply all writes in a second pass — one layout flush instead of N.oninputcalledsavePanelPrefs()on every tick during a drag, which stringifies prefs for every panel (callinghw.getInverted()/getLefty()/getMastery()etc.) and writes to localStorage — potentially dozens of times per drag. AddedsavePanelPrefsDebounced()(300ms coalescing); the slider handler now uses it.savePanelPrefs()itself cancels any pending debounce timer so every existing direct call site (includingstopSplitScreen's teardown-time save) still wins and flushes immediately, avoiding a stale debounced write clobberingsplitscreenPanelPrefsafter teardown.Also audited (per CLAUDE.md's documented behavior) and confirmed already correct, no change needed: the popup/LAN time broadcaster's
popups.size === 0 && !_lanSharegate, andstartTimeSync's 60fps loop (no redundant DOM queries inside it).Bumped
plugin.jsonversion1.14.2→1.14.3(patch), matching this repo's established convention.Testing
node -c screen.js— cleannode tests/screen.test.js— 33/33 passing, before and afterGenerated by Claude Code