Skip to content

Editor: much faster drawing and dragging of shapes (shadows, background, canvas texture) - #2

Merged
ZeroDay-Labz merged 2 commits into
ZeroDay-Labz:mainfrom
plexscript:perf/editor-drawing
Oct 19, 2026
Merged

ZeroDay-Labz merged 2 commits into
ZeroDay-Labz:mainfrom
plexscript:perf/editor-drawing

Conversation

@plexscript

Copy link
Copy Markdown
Contributor

The Editor re-renders the canvas tile on every frame of a drag, resize or pen stroke. Most of that time went into work proportional to the whole tile rather than to the objects being drawn, so drawing and moving shapes felt slow, especially with drop shadows. This PR removes that work without changing the rendered output.

Results

I measured with a 2176×1224 canvas tile: a 1440p capture at fit zoom, four large shapes with drop shadows (one is an arrow), a 50% opacity shape and a Blur region.

Before After
Full render 1483 ms 49 ms
Background only 33 ms 1.7 ms
Objects without shadow/opacity 42 ms 12 ms
  • The output is byte-identical to the current renderer for this scene.
  • Clipped tiles also match the current renderer pixel for pixel. This includes one tile that differs from the full render where a shape is cut at the tile edge, which is existing behaviour.

Renderer (linkshot-render)

  • Shadow / opacity / rotation layers. These used to allocate a full-tile layer, clone the whole tile as a backdrop, then tint, blur and composite the full tile.
    • The backdrop is now only cloned for Blur/Magnify, the only objects that read it.
    • The shadow and the composite now work on the painted part of the layer, found with painted_bounds. The shadow area is padded by 3.5σ, past the reach of the three box passes.
  • Shadow blur (blur::shadow):
    • Only the alpha channel is blurred, since a shadow is one colour.
    • Lookup tables replace the per-pixel float maths for the tint and fill.
    • A reciprocal multiply replaces the per-pixel integer divide. It's exact for every radius below 2048, which a new test checks, with a fallback for larger ones.
    • Transposes run in 32×32 blocks.
  • Compositing. blend_over uses the same float arithmetic as the highp pipeline behind draw_pixmap (load_8888 → scale_1_float → source_over → store_8888, round half to even). The results match exactly, without the per-pixel pipeline overhead.
  • Background.
    • bg_cache, bg_scaled and img_cache returned a full clone of the decoded capture on every lookup, about 15 MB per frame for a 1440p capture and far more for scrolling captures. They now hand out Arcs.
    • Cached backgrounds record whether they are opaque. An opaque background at a whole-pixel offset is copied row by row, and when it covers the tile, the checkerboard and canvas fill underneath are skipped.

Editor (linkshot-app)

  • The canvas texture is built straight from the premultiplied pixmap (ColorImage::from_rgba_premultiplied). It no longer goes through two conversion passes per re-render: unpremultiply in pixmap_to_image, then premultiply again in from_rgba_unmultiplied.
  • bump() now updates changed_at. The tray thumbnail therefore waits until a drag pauses, as its comment intends, instead of re-rendering the whole page on every frame.

Testing

  • cargo test -p linkshot-render -p linkshot-core passes, including a new exactness test for the reciprocal division.
  • Compared before/after with a throwaway benchmark: rendered output byte-for-byte, timing, and clipped tiles against the full render.
  • Cross-built the Windows exe and tried it by hand on Windows: drawing and dragging shapes is much faster.
  • This PR is independent of Editor: fix window jiggle while moving, add edge/corner resizing #1.

🤖 Generated with Claude Code

plexscript and others added 2 commits October 19, 2026 15:59
…eap to redraw

The editor re-renders the canvas tile on every frame of a drag, and most of that time went into
work proportional to the whole tile rather than to the objects:

- Objects with a drop shadow, opacity or rotation allocated a full-tile layer, cloned the whole
  tile as a backdrop, then tinted, blurred and composited the full tile for the shadow and the
  layer. Now the backdrop is only cloned for Blur/Magnify (the only objects that read it), and the
  shadow and the composite work on the painted part of the layer (padded by the blur's reach).
- Shadows blur only the alpha channel (a shadow is one colour), with lookup tables for the tint and
  fill, a reciprocal multiply instead of a per-pixel divide and a blocked transpose.
- The layer and shadow are blended with a direct loop that uses the same float arithmetic as the
  highp pipeline behind draw_pixmap (load, scale_1_float, source_over, round half to even).
- The background caches returned a full clone of the decoded (and the downscaled) capture on every
  lookup. They now hand out Arc references, record whether the bitmap is opaque, and an opaque
  background at a whole-pixel offset is copied row by row; when it covers the tile, the
  checkerboard and canvas fill under it are skipped. Image/stamp objects share the same way.

A 2176x1224 canvas tile with four large shadowed shapes, an arrow, a 50% opacity shape and a Blur
region went from 1483 ms to 49 ms per render, with byte-identical output to the previous renderer;
clipped tiles match the old renderer too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le dragging

- tiny-skia pixmaps are premultiplied RGBA, which is what egui's ColorImage stores, so the canvas
  texture is built straight from the pixmap instead of unpremultiplying it (pixmap_to_image) and
  premultiplying it again (from_rgba_unmultiplied) on every re-render.
- bump() (called on every frame of a drag, resize, pen stroke) now updates changed_at, so the tray
  thumbnail waits until the edit pauses as intended instead of re-rendering the page every frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZeroDay-Labz
ZeroDay-Labz merged commit a3a79f6 into ZeroDay-Labz:main Oct 19, 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