A deep dive into implementing a 1D PDE-based wave simulation in Jetpack Compose, comparing three rendering approaches: AGSL RenderEffect, AGSL via Canvas, and classic Canvas with Path API. The simulation uses three float buffers (prev, curr, next) for wave state, with touch impulses injected directly into the wave state. Performance analysis via HWUI profiling reveals that the classic Canvas Path renderer outperforms AGSL RenderEffect for this use case, because RenderEffect applies a full-layer per-pixel shader pass that increases GPU present/sync cost. Key optimization tips include using mutable buffers over immutable state, reducing simulation sample count, applying interpolation at render time, using drawWithCache over remember(), and stopping simulation when the wave settles. AGSL RenderEffect excels at per-pixel effects but suffers from lack of persistent GPU buffers, forcing CPU-driven state uploads each frame.

14m read timeFrom proandroiddev.com
Post cover image
Table of contents
Common Optimization Pitfalls and Performance TipsGet Yuriy Skul ’s stories in your inbox

Sort: