KatInterview

Design a Performant Continuous Particle Blaster on iOS

System DesignModel answer
MediumModel answerSystem DesigniOSCore AnimationConcurrency

Last updated

Architect an iOS animation system that emits floating emoji particles on continuous press, focusing on frame rates, layer management, timer accuracy, and unit testability.

You are tasked with building an iOS feature where holding down a button continuously launches emoji projectiles that float from the bottom to the top of the screen.

Walk through your architecture and design decisions for this system, addressing:

  1. Framework Choice: Compare rendering approaches (e.g., SwiftUI, UIKit Views, Core Animation CALayer, CAEmitterLayer, UIKit Dynamics, SpriteKit) and defend your selection for high-performance rendering.
  2. Gesture & Timing Logic: How to handle continuous press events cleanly (including edge cases) and ensure smooth, un-throttled firing timers on the main run loop.
  3. Memory & Lifecycle Management: Techniques for managing off-screen cleanup, preventing allocation churn during rapid firing, and maintaining predictable performance under heavy loads.
  4. Collision & Interactivity (Optional Extension): How you would approach hit-testing or collision detection if these projectiles needed to hit target targets on screen.
  5. Architecture & Testability: How to structure the logic so that touch state transitions and firing schedules can be verified using unit tests without relying on UIKit dependencies or actual waiting.

Hints

Hint 1

Think about thread separation: which render server runs Core Animation vs. main-thread layout engines?

Hint 2

Consider standard `Timer` behaviors during scrolling or touch tracking modes in `RunLoop`.

Hint 3

How can offscreen texture pre-rendering prevent text-layout bottlenecks during high-frequency spawns?