Skip to content

Fix/canvas overlay layer for performance - #877

Closed
ivanruizcode wants to merge 1 commit into
Lemoncode:devfrom
ivanruizcode:fix/canvas-overlay-layer-perf
Closed

Fix/canvas overlay layer for performance#877
ivanruizcode wants to merge 1 commit into
Lemoncode:devfrom
ivanruizcode:fix/canvas-overlay-layer-perf

Conversation

@ivanruizcode

Copy link
Copy Markdown
Collaborator

This change splits the canvas content into two Konva layers. Until now, all shapes, the Transformer, the snap guide lines, and the rubber-band selection rectangle lived on a single . Since Konva's batchDraw re-rasterizes the entire layer whenever any node changes, every per-frame update of the selection rectangle or the snap guides forced a redraw of every shape on the canvas. With many elements on screen this caused noticeable stutters, especially during rubber-band selection.

The fix moves the snap lines and the selection rectangle onto a new overlay layer with listening={false}, so their per-frame updates only re-rasterize that layer (a couple of purely visual nodes) instead of the shapes layer. The listening={false} flag also prevents Konva from maintaining a hit canvas for those nodes and stops them from intercepting pointer events meant for the Stage. The Transformer is deliberately kept on the main layer, because dragging it moves the shape nodes along with it (they redraw together anyway, so relocating it would bring no benefit) and because the e2e helpers locate it there. The change is additive and low-risk (typecheck and canvas unit tests pass); it targets Konva's rasterization cost, not React's reconciliation, which remains the next optimization step.

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