Memory and GC Optimization for Continuous Procedural Synthesis & Mobile Vector Outline Drawing
The Challenge: Real-time audio generation (calculating and loading wave buffers at 44.1kHz on the fly) caused brief stuttering frames on mobile due to massive Garbage Collection (GC) spikes. Additionally, rendering smooth text outlines via vector draw calls lagged on older mobile processors.
The Solution: We refactored the synthesis loops to completely eliminate allocations. Instead of creating and discarding PackedByteArray chunks on every frame, we pre-allocate a single static byte array and resize it only at musical boundaries (chord or tempo changes). We inlined the core mathematical calculations (Sine, Square, Triangle, Noise) to avoid function stack overhead. For the typography outlines, we migrated from vector shader drawings to native mobile text outline rasterization, instantly reclaiming 4.5ms of frame time.