Skip to content

perf(mobile): bake the splatter backdrop into one PNG - #77

Merged
BreakTheBeta merged 1 commit into
mainfrom
perf/mobile-bake-splatter-backdrop
Sep 30, 2026
Merged

BreakTheBeta merged 1 commit into
mainfrom
perf/mobile-bake-splatter-backdrop

Conversation

@BreakTheBeta

Copy link
Copy Markdown
Owner

Problem

With the splatter backdrop on (for example, the Codex theme), the mobile thread screen stutters when scrolling. expo-image never turns SVGs into bitmaps: Android wraps them in a PictureDrawable that redraws every vector op on each draw, and iOS holds a vector UIImage. The backdrop is about 5,000 paths (field plus two corner clusters, around 700 kB of base64) sitting under the scrolling feed, with a full-screen repeating grain layer blended on top. So every scrolled frame re-rasterized all of it.

Fix

  • One baked image. renderSplatterPreview composes the field, today's merges, both clusters and the grain into a single SVG. The new useBakedSvg (apps/mobile/src/lib/bakedSvg.ts) rasterizes it once to a PNG in the app cache, named by a hash of the markup plus the pixel size, and the thread screen paints that bitmap.
    • Android goes through expo-image's cache write, which encodes a PNG. expo-image-manipulator can't be used there because it rejects SVG drawables.
    • iOS goes through ImageManipulator → saveAsync as PNG.
    • Restarts reuse the file, concurrent bakes of the same image are shared, and the oldest files are deleted past 64.
  • One bake for every posture. The bake is a square at least 1000 pt on a side (covering tall phones and unfolded foldables), shown centre-cropped with cover. Folding, unfolding and rotating reuse the same bitmap. Clusters and merges lay out in the phone-shaped column a phone sees, so a folded phone looks as it did before, and wider screens get more field around it. Clusters now draw past their boxes instead of clipping, which also removes an old hard edge near the bottom of the phone screen.
  • Grain baked in. scripts/generate-canvas-grain.ts now writes the tile as a base64 module (apps/mobile/src/lib/canvasGrain.ts, byte-identical to the old PNG). The bake tiles it as an SVG <pattern> at the same size and opacity, and the separate Image layer is removed.
  • Settings thumbnails in Appearance → Splatter bake the same way; they had the same vector-in-a-scrolling-list problem.

Web and desktop are unchanged on purpose. Chromium already rasterizes SVG CSS backgrounds into cached bitmaps at the drawn scale, so the gain there is unproven, and a manual bake would re-bake on every window, sidebar or panel resize. That's worth revisiting only if a trace shows the backdrop in raster time.

Before / after

These are headless renders of the backdrop artwork (librsvg via sharp), not in-app screenshots. Device access and the desktop app weren't available when this was opened; in-app captures will follow. Codex theme, dark, default settings, 2×. Left is before, right is after.

Phone (412×915):

phone before/after

Unfolded foldable (930×775): the phone composition sits in the middle, with field around it.

unfolded foldable before/after

Tablet (1024×1366):

tablet before/after

Verification

  • packages/shared: splatterBackdrop.test.ts and mergeSplatters.test.ts pass (29), including new cases for frame layout, merges and grain ordering.
  • Typecheck is clean for the touched files in shared, mobile and web. The mobile package has unrelated existing errors elsewhere.
  • node scripts/generate-canvas-grain.ts --check passes.
  • Not yet verified on a device:
    • Both native bake paths (Android's cache write, iOS's manipulator).
    • Whether iOS CoreSVG renders the <pattern>/<image> grain and overflow="visible". If it doesn't, the grain disappears or clusters clip to their boxes on iOS; the splatter itself still renders.
    • Scroll performance on a real device.
  • Memory: the bake is one bitmap of about 1000 × pixel ratio on each side (about 27 MB at 2.625×, 36 MB at 3×). It replaces three vector drawables and a grain layer.

Done by Claude Opus 5.5 (1M context) in Claude Code via T3 Code.

🤖 Generated with Claude Code

expo-image keeps SVGs as vectors (Android replays a PictureDrawable on every
draw, iOS holds a vector UIImage), so the ~5,000-path backdrop behind the
thread feed was re-rasterized on every scrolled frame, with a full-screen
grain layer blended over it.

The field, merges, clusters and grain now compose into one SVG that is baked
to a PNG once, cached on disk by markup and pixel size, and shown as a bitmap.
The bake is a square covering tall phones and unfolded foldables, so folding
and rotating reuse it; clusters and merges lay out in the phone-shaped column
a phone sees. The settings pattern thumbnails bake the same way.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 30, 2026
@BreakTheBeta
BreakTheBeta merged commit 5eaeaaf into main Sep 30, 2026
12 of 17 checks passed
@BreakTheBeta
BreakTheBeta deleted the perf/mobile-bake-splatter-backdrop branch September 30, 2026 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant