A guide to speeding up your video processing with AlphaEvolve Google and DoIt used AlphaEvolve, Google Cloud's autonomous evolutionary code-optimization tool, to optimize production Swift code in a live macOS streaming app, uncovering performance headroom that manual profiling missed. AlphaEvolve pairs a Gemini model ensemble running on Google Cloud with a customer-managed evaluator that compiles and times native Swift/Metal code against a reference webcam clip, scoring candidates with metrics such as Structural Similarity Index (SSIM). The approach targets real-time video budgets of 33.3 ms per frame at 30 fps and 16.6 ms at 60 fps, and the split-loop pattern is presented as applicable to microservice throughput, database queries, ML tensor pipelines, and embedded systems. In real-time streaming, every millisecond counts. For example, at 30 frames per second fps , developers have a strict frame budget of just 33.3 ms and only 16.6 ms at 60 fps to ingest camera frames, run neural segmentation, apply shaders, and composite output. Exceeding that budget by even a fraction of a millisecond leads to dropped frames and stuttering. Manual optimization is notoriously tedious — requiring weeks of analyzing flame graphs and hand-tuning low-level code in Swift, C++, or Metal. While standard AI coding assistants can generate boilerplate, they can’t optimize against target hardware, benchmark real-world latency, or ensure optimizations preserve visual fidelity. Autonomous, closed-loop evolutionary optimization changes this paradigm. Tools like AlphaEvolve https://cloud.google.com/blog/products/ai-machine-learning/alphaevolve-is-available-for-everyone?e=0&utm source=gemini pair cloud-scale model reasoning with local hardware execution, and we’re already seeing real-world impact. In partnership with Google, DoIt https://www.doit.com/about?utm source=gemini used AlphaEvolve to autonomously optimize production Swift code in a live macOS streaming app, uncovering performance headroom that manual profiling missed read the full technical writeup https://medium.com/google-cloud/running-alphaevolve-on-your-own-code-f8aeebceb4d0?utm source=gemini . While this post focuses on video pipelines, the split-loop pattern applies anywhere performance matters — from microservice throughput and database queries to ML tensor pipelines and embedded systems. In every case, the formula is the same: pair Gemini code generation in the cloud with your domain-specific benchmark harness and automated quality gates. Today, we’ll show you how to use AlphaEvolve to speed up video processing—and apply these principles to your own performance bottlenecks: Understanding the split-loop architecture: How AlphaEvolve decouples managed cloud generation Gemini model ensemble on Google Cloud from local evaluation e.g. compiling and timing native Swift/Metal code . Evaluator craft and quality gates: How to construct scoring functions using metrics like Structural Similarity Index SSIM to prevent evolutionary loops from gaming the benchmark e.g., skipping rendering entirely to go fast . Autonomous algorithmic discovery: How Gemini-driven evolutionary search can autonomously discover unprompted framework APIs and make intelligent engineering trade-offs e.g., frame-caching limits . Setting realistic performance boundaries: How to measure code optimization against physical hardware floors. AlphaEvolve runs a closed-loop evolutionary process: given a seed program and a custom scoring function, a mixture of Gemini models proposes code variations, executes the scoring function against each candidate, keeps the highest-performing code, and iteratively climbs toward an optimal solution over multiple generations. A core architectural advantage of AlphaEvolve is its clean separation into two halves: The generation half Google Cloud managed service : Contains the prompt sampler, Gemini model ensemble, and program database. Google Cloud handles the scale, prompt orchestration, and generation mechanics. The evaluation half customer managed compute : Scoring code quality is strictly domain-specific. You own the evaluator module entirely, running it on your own hardware or target architecture in this case, macOS running native Swift code . While AlphaEvolve is Python-first on the cloud generation side, evaluation can be written in any language. The custom evaluator compiles each Swift candidate using swift and executes it against a standard reference webcam clip. An automated optimization loop like AlphaEvolve never actually "sees" your video stream. It only sees the numeric fitness score your evaluator returns. If your evaluation metric has a blind spot, evolutionary code generation will aggressively exploit it. In our early runs, a naive fitness score weighted toward raw latency produced an astonishing speedup: the model simply bypassed blur rendering entirely and returned unmodified frames in 0 ms. Structural Similarity Index Measure SSIM : To prevent the model from gaming your benchmark, try building a two-tiered scoring function that pairs throughput with structural fidelity metrics like Structural Similarity Index SSIM : What does this give you? The ability to test against worst-case clips: Never benchmark on static frames or blank cameras. Candidate code can easily pass an average SSIM gate on static backgrounds while failing completely during quick head turns. You can track the minimum, not just the mean: Enforce both an average threshold and a per-frame floor to catch dropped frames or delayed mask updates. Most developers use generative AI for local micro-optimizations e.g., inlining helper functions, unrolling loops, or tweaking memory pools . But when given architectural room, the evolutionary loop can discover systemic optimizations on its own. Provide framework context, not isolated loops: Include public SDK headers, interface definitions, or API reference symbols in the prompt or retrieval harness. An LLM cannot adopt a sequence-aware subsystem if its context window only contains an isolated frame-processing callback. Expose multi-frame lifecycle hooks: Let your candidate code maintain a bounded state across executions e.g., historical masks or cache timestamps rather than enforcing pure, stateless functions. Let quality gates police the trade-offs: When AlphaEvolve introduced temporal mask caching, it initially cached masks too aggressively, causing noticeable trailing artifacts. Because our SSIM gate penalized drift during motion, the search converged on a production-ready cache window without manual parameter tuning. A common pitfall in performance engineering is optimizing in the dark. If you achieve a 2x speedup, is that an incredible achievement, or did you leave another 3x on the table? In real-time media, total frame time splits into two distinct categories: Mutable software overhead: Memory allocations, buffer format conversions, thread context switches, and API dispatch friction. Immutable hardware floors: Raw Neural Engine inference latency, GPU shader compute time, and hardware display synchronization. Before running optimization loops, here’s a few principles to keep in mind: Build a "no-op" pipeline: Strip out Swift/C++ orchestration, data marshalling, and frame conversions. Dispatch only the pre-warmed ML model and bare GPU pass on a dummy buffer. The resulting time is your physical hardware lower bound. Calculate your addressable ceiling: Your total possible optimization potential is: 3. Score against the hardware gap: Instead of arbitrary speedup multiples, measure optimization efficiency: All benchmark code, test clips, evaluation scripts, and raw candidate logs are open source: GitHub repository: AlphaEvolve Camera Background Blur Example https://github.com/SaschaHeyer/gen-ai-livestream/tree/main/alphaevolve/examples/camera-background-blur Detailed technical write-up of our case study with DoIt: Running AlphaEvolve on Your Own Code https://medium.com/google-cloud/running-alphaevolve-on-your-own-code-f8aeebceb4d0