TL;DR
- Oversized bitmaps relative to the UI slot cause most bloat and OOM crashes: exporting 1080p bitmaps or full-canvas transparent padding for a 240 × 240 badge punishes both download time and mobile RAM.
- Separate wire size from decoded RGBA memory: players decode every embedded image to uncompressed 32-bit RGBA textures (
∑ width × height × 4bytes; see the format specification). PNG-8 quantization reduces wire bytes without lowering pixel RAM; resizing bitmaps reduces both. - Avoid naive
canvas.toBlob('image/png')re-encoding: browsers serialize Canvas PNGs as 32-bit truecolor RGBA, which regularly inflates already-indexed PNG-8 assets. - Inspect before compressing: inspect the asset list in the SVGA Online Player or run the Python inspection script to catch orphan assets, duplicate bitmaps, and oversized dimensions first.
What each optimization actually reduces
| Technique | Reduces wire bytes | Reduces decoded RAM (∑ w × h × 4) |
Visual trade-off | Best target |
|---|---|---|---|---|
Remove orphan keys + SHA-256 dedupe + zlib level 9 |
Yes (lossless) | Yes (eliminates duplicate textures) | None | Any SVGA 2.0 with unreferenced or duplicate assets |
| Crop transparent padding + resize bitmaps/canvas to 2× UI slot | Yes (major) | Yes (scales quadratically with dimensions) | Negligible when matched to display slot | Small badges/effects using oversized or full-screen PNGs |
| PNG-8 palette quantization with preserved alpha | Yes (often substantial) | No (pixel dimensions stay the same) | Slight (smooth gradients may band) | Flat graphics, glow sprites, text badges |
Trim redundant hold frames + tune FPS (30 → 20/15) |
Yes | Yes (fewer unique bitmaps) | Slightly less fluid motion | Frame-by-frame bitmap sequences |
| Lower MP3 bitrate or strip unused audio | Yes | No direct texture RAM change | Lower audio bitrate or silent | Assets with oversized MP3s or targeting Web Lite |
Six-step bloat triage workflow
Step 1: Inspect largest bitmaps, orphans, and duplicates in the viewer
Drop your .svga file into the SVGA Online Player to inspect assets ordered by encoded size and pixel dimensions, or run inspect_svga.py from the SVGA Python guide in CI. Look for two zero-risk wins first:
- Orphan entries: keys inside
MovieEntity.imagesthat are never referenced by anySpriteEntity.imageKey,SpriteEntity.matteKey, orAudioEntity.audioKey. Important: never delete a placeholder bitmap if a sprite’simageKeyuses it for runtimesetImageorsetTextoverrides. - Duplicate bitmaps: identical PNG payloads (matching SHA-256 hashes) stored under separate keys across static frames. Deduplicate to a single
imageKeyand point all matching sprites to it.
Step 2: Resize the canvas and bitmaps to the actual UI slot
Compare each asset’s pixel dimensions against the slot where it renders:
- If a gift badge renders inside a
240 × 240 ptcontainer, exporting at 2× (480 × 480 px) is sufficient. Remove 4K source textures or bitmaps larger than the viewport. - Crop empty transparent borders around small corner elements in After Effects or Animate before exporting. A single
1024 × 1024bitmap always occupies1024 × 1024 × 4 = 4 MiBof decoded RGBA texture memory even if most of its pixels are transparent. - When downscaling an existing SVGA programmatically, scale
MovieParams.viewBoxWidth/Height,FrameEntity.layout,Transform.tx/ty, andShapeEntitycoordinates by the exact same factor.
Step 3: Apply alpha-preserving PNG-8 quantization instead of 32-bit RGBA
Many UI and gift bitmaps use limited color palettes yet ship as 32-bit truecolor RGBA PNGs. Quantizing to 256, 128, or 64 colors with full 8-bit tRNS alpha (using tools such as pngquant, browser upng, or Pillow Image.quantize(colors=256, method=Image.Quantize.FASTOCTREE)) shrinks compressed image size while keeping smooth transparent edges. Always pair this with Step 2 when mobile RAM is tight, since PNG-8 does not alter decoded width × height × 4 memory.
Step 4: Trim trailing hold frames and tune FPS
- Trailing static frames: if an animation holds still for 1–2 seconds at the end, avoid exporting dozens of redundant frames; hold on the final frame in player config or trim extra frames.
- Frame rate: frame-by-frame bitmap exports at 30 or 60 FPS often run cleanly at 24, 20, or 15 FPS, directly cutting unique bitmap count. Pure transform-interpolated vector/sprite layers need no FPS reduction because matrix deltas compress well under
zlib.
Step 5: Audit embedded audio (AudioEntity)
Check MovieEntity.audios:
- If your target clients include
SVGAPlayer-Web-Lite(which ignores embedded audio) or the slot plays muted, stripaudiosand their blobs fromimages. - When audio is required, short sound cues rarely need 320 kbps stereo MP3; encoding mono cues at 64–96 kbps keeps payload predictable.
Step 6: Re-evaluate the format for long photographic or 3D sequences
If an animation still exceeds budget after Steps 1–5 because it consists of multi-second full-bleed 3D particle renders with unique pixel content on every frame, per-frame PNG packaging hits a structural ceiling. Compare hardware-decoded video alternatives like VAP, YYEVA, or PAG BMP mode in the SVGA format comparison guide.
Why did my SVGA get larger after compression?
Four real engineering behaviors explain why a re-packed .svga sometimes ends up larger than the input:
- Canvas 32-bit RGBA re-encoding: calling
canvas.toBlob('image/png')or saving through a default image pipeline converts compact indexed PNG-8 images back into 32-bit truecolor RGBA, ballooning byte size. - Already-optimized source PNGs: if the original export already used
pngquantplusoxipngorzopfli, re-running a generic encoder adds header and filter overhead without finding extra savings. - Rasterizing
ShapeEntityvectors: workflows that flatten vectorSHAPE/RECT/ELLIPSElayers into PNG bitmaps replace a few hundred bytes of Protobuf geometry with full pixel buffers. - Low
zliblevel or lost deduplication: writing the outer container atzliblevel 1 (or uncompressed ZIP store in 1.x) or duplicating sharedimageKeyentries negates bitmap savings.
Whenever re-encoding grows the file, keep the original bitmaps and apply only lossless cleanup (orphan removal, SHA-256 deduplication, and zlib level 9).
Six-point post-compression QA checklist
- Dark and light checkerboard alpha fringe check: play both original and compressed files in the SVGA Online Player across dark (
#000000), light (#ffffff), and neutral backgrounds to catch dark/white halos or gradient banding. - Small text and hairline legibility: inspect badge labels and 1 px strokes at actual target device size.
- Dynamic slot & mask integrity: verify every
imageKeyused forsetImage/setTextand everymatteKeytrack-matte reference remains intact. - Audio sync check: if FPS or frame count changed, confirm
AudioEntity.startFrameandendFramestill match visual timing. - Version compatibility check: ensure output is SVGA 2.0 (
zlib+MovieEntity) when targetingSVGAPlayer-Web-Liteorflutter_svga(see the integration guide). - Three-loop low-end device memory check: run three back-to-back playback cycles on a low-end device and verify memory stabilizes and frees cleanly on stop.
Reproducible open-source benchmarks
Instead of relying on synthetic estimates, inspect the real measurements generated directly from files on disk in the SVGA test samples library (featuring v2-compression-bench and index-example) and the downloadable /data/svga-benchmark.json dataset, complete with SHA-256 checksums, exact wire byte deltas, and decoded RGBA memory calculations.
To run orphan cleanup, SHA-256 deduplication, canvas downscaling, alpha-preserving PNG-8 quantization, audio stripping, and side-by-side comparison directly in your browser without file uploads, open the SVGA Online Compressor.
