Skip to content

perf: reduce snapshot rendering time and memory usage - #129

Open
so1ve wants to merge 1 commit into
codesnap-rs:mainfrom
so1ve:perf/rendering
Open

so1ve wants to merge 1 commit into
codesnap-rs:mainfrom
so1ve:perf/rendering

Conversation

@so1ve

@so1ve so1ve commented Sep 7, 2026

Copy link
Copy Markdown

DISCLAIMER: Most of the code in this PR was generated with AI assistance

Large snapshots become expensive once the canvas exceeds tiny-skia's 8191 px tiling threshold: drawing individual glyph samples repeatedly traverses canvas tiles, while full-canvas buffers increase memory usage.

This change:

  • Composites glyph samples directly, preserving tiny-skia's blending and coverage rounding
  • Prepares layout, highlighting, and text shaping once
  • Reuses repeating background and shadow rows
  • Allows transferring rendered pixels without copying the full canvas

My local benchmark with 800 lines of code:

Metric Before After
Elapsed time ~20–22 s ~2.1 s
Peak memory ~1,247 MiB ~40 MiB

Strip clipping still produce small anti-aliasing differences at fractional rounded corners but I think that's tolerable

- Composite glyph pixels directly to avoid per-sample canvas traversal
- Render and encode PNGs in strips without allocating a full canvas
- Reuse prepared text and repeated background and shadow rows
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