Building PaperConfetti: A Better Celebration for SwiftUI

In 2022, I contributed more realistic physics to ConfettiSwiftUI. I was building Wordie, and guessing the mystery word deserved a little celebration. Apparently I had strong opinions about how imaginary paper should fall.

Four years later, I still do.

Wordie’s celebration had grown into five cannons, one at each letter of the winning word, firing 180 pieces in total. The letters dropped into place, the keyboard disappeared, and confetti crossed the board. It was a lovely moment, except for the occasional hitch.

That started PaperConfetti: an iOS 16+ Swift package with thirteen paper shapes, flat and 3D appearances, and a simple pop() API. It uses Core Animation’s CAEmitterLayer for playback. I worked with a coding agent on the implementation and tests, then reviewed the motion on my iPhone.

Here’s how to use it, followed by the decisions that mattered most: stable coordinates, varied motion, tests for missing particles, and measurements that distinguish low CPU usage from smooth animation.

Give the celebration a stable home

The first fix wasn’t a new renderer. Wordie’s last two turns add rows, and winning changes the keyboard and result layout. A cannon attached to a moving letter cell can make already launched paper jump with it.

We captured the winning letters’ positions once and placed the celebration in a stable overlay. That lesson applies to either renderer: use one coordinate system for the launch positions and the overlay, and keep the overlay outside the layout animation. Capturing a point won’t help if its entire coordinate system moves afterward.

Wordie's win flow with 180 pieces: historical ConfettiSwiftUI first, PaperConfetti second. Recorded on the same simulator to show the integration and appearance; this is not physical-device performance evidence.

Add a pop to SwiftUI

Add https://github.com/twhitt14/PaperConfetti.git through Xcode’s Add Package Dependencies, select version 0.2.0, and add the PaperConfetti product to your app target. This complete view uses its default 3D appearance, offers a flat alternative, and lets the user cancel:

import SwiftUI
import PaperConfetti

struct ConfettiDemo: View {
    @StateObject private var confetti = ConfettiController()

    var body: some View {
        VStack(spacing: 24) {
            Text("A little celebration").font(.title)
            Button("Celebrate") {
                confetti.pop()
            }
            Button("Flat paper") {
                confetti.pop(configuration: .init(appearance: .flat))
            }
            Button("Stop") {
                confetti.cancel()
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .confettiOverlay(confetti)
    }
}

Own one controller per overlay with @StateObject. The default pop starts at the container’s bottom center and requests 80 pieces; Wordie’s five-cannon setup is a separate configuration. A new pop replaces the previous burst, keeping work bounded. Calling pop() again is an explicit event, even when an advanced caller reuses the same seeded burst.

The SwiftUI wrapper passes touches through, respects Reduce Motion, and cancels when the scene becomes inactive or the overlay leaves the screen. Canceled celebrations don’t replay on return. Keep success text and other meaningful feedback in your app; confetti is decoration. UIKit hosts can use ConfettiLayerView directly, but must supply their own Reduce Motion and scene policy.

The package README covers individually positioned and delayed cannons, palettes, shapes, sizes and motion. Rendering is for iOS and iPadOS; the macOS target exposes the physics model for tests, not an AppKit confetti view.

Choose a renderer, then keep the public API small

ConfettiSwiftUI gave Wordie years of celebrations. It also supports text and emoji, which PaperConfetti doesn’t attempt to replace. Our historical comparison pins ConfettiSwiftUI 1.1.0, revision f45961f, rather than claiming to represent every version of the library.

We tried per-piece SwiftUI animation, Canvas, Core Animation layers, emitter particles, and SpriteKit variants. The first PaperConfetti layer renderer used 89–91% less cumulative app CPU than that historical baseline in one matched classic-shape study, yet could still visibly hitch with 720 complex pieces. The October 27 results describe that earlier 0.1 renderer, not the current one. Lower CPU was useful progress, not proof that the animation was finished.

The selected 0.2.0 implementation prepares trajectories, shared textures and a bounded tree of emitter layers and animations once per pop. Core Animation handles playback: no SwiftUI view per piece, app display-link callback advancing every particle, or per-particle timer. Flat and 3D are appearances of this same engine.

This doesn’t make rendering free. Preparation costs app CPU; compositing and drawing cost work elsewhere. Apple’s Core Animation guide explains cached image playback, and its render-loop talk explains why timely frame delivery depends on more than the app’s CPU number.

The other prototypes helped us choose. They didn’t need to become permanent API options that every caller has to understand.

Make the pieces behave like different pieces

The thirteen silhouettes include stars, curved streamers, a hollow ring and other paper cuts. Original Core Graphics paths become small, shared CGImage textures. Narrow pieces keep their proportions, and cached starting orientations prevent identical neighbors from all presenting the same face. The 3D appearance adds out-of-plane tilt to the spin; flat mode uses the same flight timing.

Early emitter particles were smooth but oddly lifeless. Similar pieces moved together, and the top of the blast looked like a shelf where everyone stopped for a meeting.

Two changes helped. First, each piece gets its own rise time. For normalized rise progress u, displacement follows 2u − u²; descent follows v², where v is normalized descent progress. For upward-fired pieces, vertical velocity reaches zero at the peak and immediately starts increasing downward. There is no explicit pause. Different rise and fall durations suggest a quick launch and a lighter descent; this is an art-directed model, not an aerodynamic simulation.

Second, shapes get different base fall-speed tendencies, with another ±20% descent-duration variation per piece. Seeded variation in reach and direction softens the burst’s outer edge instead of crowding every piece against one radius. Consequently, radius is a nominal reach, not a hard boundary. A fixed seed makes comparisons repeatable without making every ribbon move in lockstep.

Test for the cannon that never fired

At 5,760 requested pieces, an early emitter implementation sometimes failed to show the first cannon. An undocumented particle limit seemed plausible. We needed a test that could distinguish a smooth complete effect from a smooth incomplete one.

Five cannons occupied separate visible regions; another probe placed 5,760 requested pieces in inspectable grid slots. Replays and an intentional main-thread stall exercised startup. The failure pointed to emission timing: a very short birth window could expire before the render server visited the large tree. Creating objects didn’t prove they had produced visible particles. Apple’s birthRate is a rate, not an exact “draw this many now” command.

The fix prepares all cannons under a shared paused clock, then starts them together with headroom. A low-rate emission schedule is advanced to its first birth; its next birth falls beyond the burst’s lifetime and cleanup. Cannon delays control visible flight rather than separate short birth windows.

The important test was the negative control: deliberately expire the old window beside a sustained live reference. The test has to detect the missing region and the healthy reference. Otherwise, an empty screenshot could masquerade as a passing test.

The final implementation passed simulator pixel checks and all three physical iPhone emission regressions, covering repeated five-cannon launches, the grid, and the broken-window control. These are observations on tested configurations, not a public guarantee of an exact live particle count. Confetti that never appears is very cheap to render. It is also a terrible celebration.

Measure the finished renderer

On October 29, we measured 0.2.0’s emitter renderer and finalized physics on an iPhone 18 Pro Max running iOS 27.0.1. The Release benchmark used five cannons, thirteen festive shapes, matching palettes, sizes and seeded trajectories, plus common keyboard-dismissal and scrolling work. The suite did not record the screen.

The CPU pass alternated flat and 3D within one process. Each value is the median of three measured repetitions after warm-up:

Pieces per burstFlat CPU3D CPU
180106.2 ms110.2 ms
720162.4 ms153.0 ms
5,760369.5 ms394.2 ms

These are cumulative whole-app CPU milliseconds over roughly six-second trials, not frame times or GPU costs. Recorded thermal states were nominal. The small, mixed differences on one phone don’t establish a speed winner; 3D remains the default, with flat as a visual choice.

We measured hitches separately with Animation Hitches, matching events to trial signposts. These are total hitch events across two measured bursts per cell, after warm-up:

Pieces per burstFlat hitches3D hitches
18000
72000
1,44000
2,88001
5,7601310

No hitches were recorded through 1,440 pieces in these warm trials. At 5,760, the totals were 225.0 ms flat and 145.8 ms in 3D, across the two bursts; the longest individual hitches were 50.0 ms and 16.7 ms. Recorded timing thermal states were nominal. These are instrumented event totals, not FPS or Apple’s animation-active hitch-time ratio.

That largest load is 32 times Wordie’s ordinary 180-piece celebration, not 32× faster. It also took roughly 0.36 seconds from requesting the pop until the shared clock was scheduled to start. That includes preparation and deliberate headroom, and does not measure the first visible frame. A stress demonstration is useful; it isn’t a recommended success-screen budget.

The memory pass alternated natural completion and cancellation. Settled app footprint showed no upward trend across five retained samples per mode after warm-up. This covers app memory in a short run, not all render-server/GPU memory or a universal leak guarantee.

The retained measurements and methodology include individual trials, warm-ups, source hashes and excluded captures. Some collection fixes were made in the local benchmark harness after 0.2.0; the library source remained identical to the release. These results do not establish energy savings, cold-start behavior, or a new speedup over ConfettiSwiftUI’s different historical workload.

Watch the effect—and test the interface underneath

iPhone screen recording at its original speed. Classic-shape pairs use 180, 720 and 1,800 pieces; the final two clips separately showcase thirteen festive shapes. I noticed slowdown in the recorded 5,760-piece segment. Repeating it without screen recording looked smooth to me; that repeat is an observation, not a retained measurement.

Screen recording adds work to the phone being tested. An external camera avoids that particular load, but camera cadence and display refresh still limit what footage can establish. Treat the video as a visual demonstration, separate from the instrumented measurements.

For your own app, test more than the paper:

  • Tap, toggle, scroll and navigate while the overlay is active. Decoration must not steal input.
  • Move the surrounding layout and update the parent view. Existing particles must not jump or accidentally restart.
  • Leave the screen, deactivate the scene, and cancel before a delayed start. Nothing should replay unexpectedly on return.
  • Enable Reduce Motion and confirm that meaningful success feedback remains without particles.
  • Repeat bursts and alternate cancellation with natural completion; check that active work gets cleaned up.

Those checks mattered more than adding another renderer selector. The completed October 29 run passed 14 physical UI checks, including touch-through, cancellation and the emission regressions. Missing or interrupted measurements were rejected, not counted as zero hitches.

To explore the public package, clone PaperConfetti, open Examples/PaperConfettiExample.xcodeproj, and run PaperConfettiExample on an iPhone simulator. No signing account is needed for that simulator example. For physical testing, select your signing team; the profiling guide explains the instrument passes and their limits. The article’s videos use a separate comparison host, not the public example’s exact screen.

Wordie’s celebrations still use modest particle budgets. The payoff is a small effect that belongs in the game, backed by tests that notice when it blocks a button—or forgets to appear.