The developer of the GhostGram Telegram client for Kotlin Multiplatform encountered performance issues with TGS animated stickers on Android. Initial implementation using Compottie caused high HWUI rendering latency, with some animations playing two to three times faster than in the official Telegram app.
To address the performance bottlenecks, the developer implemented a 'Frame Baking' approach. Instead of rendering vector compositions in real-time, the system uses Airbnb Lottie to pre-render animation frames into bitmaps in a background thread, which are then displayed as a sequence of images.
The system uses an LRU cache limited to 24 MiB to store pre-rendered bitmaps, with frame sizes set to 260 by 260 pixels. The number of frames is calculated based on the animation duration, capped at 90 frames, with a target of 30 FPS. The player uses withFrameNanos to synchronize playback with the Compose frame cycle.
The implementation includes mechanisms to cancel coroutines during rapid scrolling to free up memory and uses a Mutex to serialize frame preparation tasks. While the desktop version of the client continues to use Compottie, the Android version now utilizes the custom frame-baking architecture.
Testing on a Unisoc T606-based device showed that the optimized GhostGram client maintains a more stable HWUI rendering graph in static scenarios compared to the official Telegram app. However, performance spikes still occur during rapid list scrolling, which remains an area for further investigation.





