Skip to content

perf(canvas): reduce Konva churn during pan/drag in control layers#7

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-canvas-rendering-performance
Draft

perf(canvas): reduce Konva churn during pan/drag in control layers#7
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-canvas-rendering-performance

Conversation

Copy link

Copilot AI commented Mar 2, 2026

Summary

Canvas interaction degraded as object/layer counts and raster resolution increased, with panning/dragging doing too much per-frame work in the Konva stack. This PR reduces hot-path update pressure and node churn without changing rendering semantics.

  • Stage drag update pressure

    • Throttled stage attribute synchronization during dragmove with raf-throttle (instead of syncing on every drag event).
    • Added explicit teardown of the throttled callback on module destroy.
  • Dynamic grid node churn

    • Reworked dynamic grid rendering to reuse existing Konva.Line instances and update attrs in place.
    • Removed full child destruction/recreation on each render; only trims excess lines when needed.
  • Net effect

    • Fewer store/listener cascades during panning.
    • Lower allocation/GC pressure in background grid rendering under high-frequency stage updates.
// before: sync on every dragmove
onStageDragMove = (e) => {
  if (e.target !== this.konva.stage) return;
  this.syncStageAttrs();
};

// after: frame-throttled sync
onStageDragMove = (e) => {
  if (e.target !== this.konva.stage) return;
  this.syncStageAttrsThrottled();
};

UI capture from this change set:
https://github.com/user-attachments/assets/a4114e97-e075-4b17-9e55-6c5302d1e487

Related Issues / Discussions

N/A

QA Instructions

  • Open the control-layers canvas with multiple raster/regional/control layers.
  • Pan/drag and zoom repeatedly.
  • Compare interaction smoothness and responsiveness, especially while panning high-resolution content.

Merge Plan

  • Standard merge.
  • No schema/migration or rollout sequencing concerns.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)
Original prompt

Take a look at our canvas layers and rendering stack. We're using react konva, and the app slows down significantly when the number of objects increases (lots of raster layers, regional layers, ControlNet, etc.) or when panning with high resolution layers. Look for good rework targets that can net us meaningful performance improvements.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 2, 2026 23:45
Co-authored-by: dunkeroni <3298737+dunkeroni@users.noreply.github.com>
Co-authored-by: dunkeroni <3298737+dunkeroni@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor rendering stack for performance improvements perf(canvas): reduce Konva churn during pan/drag in control layers Mar 2, 2026
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