Repository navigation
perf(mobile): bake the splatter backdrop into one PNG - #77
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
PictureDrawablethat redraws every vector op on each draw, and iOS holds a vectorUIImage. 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
renderSplatterPreviewcomposes the field, today's merges, both clusters and the grain into a single SVG. The newuseBakedSvg(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.ImageManipulator→saveAsyncas PNG.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.scripts/generate-canvas-grain.tsnow 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 separateImagelayer is removed.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):
Unfolded foldable (930×775): the phone composition sits in the middle, with field around it.
Tablet (1024×1366):
Verification
packages/shared:splatterBackdrop.test.tsandmergeSplatters.test.tspass (29), including new cases for frame layout, merges and grain ordering.node scripts/generate-canvas-grain.ts --checkpasses.<pattern>/<image>grain andoverflow="visible". If it doesn't, the grain disappears or clusters clip to their boxes on iOS; the splatter itself still renders.1000 × pixel ratioon 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