perf(canvas): detach hidden layers from DOM, throttle onscreen check, increase cache#8939
Merged
lstein merged 8 commits intoApr 20, 2026
Conversation
…, increase cache - setVisibility now uses layer.remove()/stage.add() to detach/reattach hidden canvas elements from the DOM, freeing browser compositing resources - Wrap syncIsOnscreen and syncIntersectsBbox with rafThrottle to reduce redundant calculations during pan/zoom - Increase canvasElementCacheSize 32→128 and imageDataCacheSize 32→64 - Add 3-Layer-Flattening design document for future architectural optimization
dunkeroni
approved these changes
Apr 20, 2026
Collaborator
dunkeroni
left a comment
There was a problem hiding this comment.
Had some trouble testing this at first. On Firefox specifically (and possibly in the electron app) this does improve performance for hidden raster layers. On Chrome, some caching witchcraft makes it fast all the time as long as the layer data does not change, so this change is not noticeable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is Step 1 of the Canvas Optimization plan.
setVisibilitynow useslayer.remove()/stage.add()to detach/reattach hidden canvas elements from the DOM, freeing browser compositing resourcessyncIsOnscreenandsyncIntersectsBboxwithrafThrottleto reduce redundant calculations during pan/zoomcanvasElementCacheSize32→128 andimageDataCacheSize32→64Related Issues / Discussions
Performance degrades significantly with many raster layers on the canvas. Each
Konva.Layercreates a separate HTML<canvas>element — with 20+ layers, the browser compositor struggles under the load.QA Instructions
<canvas>elements in the DOMMerge Plan
No special merge considerations. No Redux slice changes, no DB schema changes.
Checklist
What's Newcopy (if doing a release after this PR)