Skip to content

perf: encode native snapshots with Rust and reuse prepared images - #46

Merged
rdlabo merged 8 commits into
mainfrom
feat/rust-snapshot-png
Nov 10, 2026
Merged

rdlabo merged 8 commits into
mainfrom
feat/rust-snapshot-png

Conversation

@rdlabo

@rdlabo rdlabo commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Native snapshot handoffs repeatedly encoded PNGs and decoded unchanged images. This PR adds a packaged Rust PNG encoder, bounded two-worker postprocessing, and reuse of eligible captures/files/decoded images. Consumers do not need Rust or an NDK.

Performance

Total time includes capture readiness, capture, copies/FFI, PNG encoding, file transport, Web image decode and drawing confirmation. Each comparison interleaved modes, excluded three warmup rounds, and measured 30 fresh captures per mode on a 12-control screen.

Platform encoder → serial Rust encoder

Environment Before p50 / p90 After p50 / p90 p50 reduction
iOS 27 simulator, PNG16 Display P3 454.07 / 493.98 ms 352.21 / 388.27 ms 22.4%
Android 15 emulator, 720p 721.75 / 1,035.36 ms 599.02 / 779.72 ms 17.0%

Serial Rust → two-worker Rust (same codec/settings)

Environment Before p50 / p90 After p50 / p90 p50 reduction
iOS simulator 355.09 / 394.38 ms 294.78 / 305.37 ms 17.0%
Android emulator 605.77 / 885.91 ms 555.29 / 871.56 ms 8.3%

These are separate experiments; their reductions must not be added. PNG size changes by +2.3% on iOS and −15.2% on Android in the encoder comparison, and is unchanged between worker modes. These fixture results are not physical-device or universal speedup claims; Android's final p90 concurrency improvement is small.

Behavior and correctness

  • Keep shared Rust notices in one canonical resource directory consumed by SwiftPM/CocoaPods and Android; retain only NDK-specific notices separately. Package checks compare every bundled notice with its original.
  • Preserve iOS 16-bit Display P3/ICC and alpha, with platform encoding fallbacks. Process large crops serially.
  • Require explicit native reuse acknowledgement before Web reuses a decoded image. Repeated unchanged preparations and entry/return add no capture, encode, file write/read or decode in the integration test.
  • Reject Android cache reuse when relative raster-crop placement or source draw order changes; retain reuse for a common translation and preserve token/file ownership.

Local validation: TypeScript/ESLint/format checks, native artifact verification, iOS image-reuse integration, and Android Kotlin formatting/Release lint passed. Four Android emulator regressions passed, including common translation, relative movement, draw-order changes and comparison against fresh-capture pixels.

@rdlabo
rdlabo merged commit 3da00a4 into main Nov 10, 2026
5 checks passed
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