← Back to Portfolio 2026.04 · 4 min read
SwiftUI PostgreSQL Performance

Cutting Mobile Cold-Start Latency by 300% with Warm Caches

Notes from building Piles in SwiftUI and Supabase/PostgreSQL: predictive preloading, local-first hydration, and eliminating waterfall waits.

By Abhinav Kumar

Fig. 02 — Request waterfall comparison: sequential cold-path hydration vs. local-first warm cache with background revalidation.

When building Piles, a native SwiftUI app for saving and organizing web content, our earliest prototypes felt sluggish on real cellular connections—even though our Supabase/PostgreSQL queries returned in under 80ms on the server.

Profiling the end-to-end user tap revealed the real culprit: client-side request waterfalls. Opening a collection waited sequentially for auth session verification, metadata rows, OpenGraph thumbnails, and reader-view HTML extraction before rendering a single interactive row.

Measuring Where the Time Actually Went

Breaking down a typical cold open on LTE showed three stacked stalls:

  • Session + query handshake (~210ms): Waiting on token refresh before firing the primary PostgreSQL read.
  • Metadata & asset fan-out (~440ms): Fetching per-item previews only after the parent list response decoded.
  • Main-thread layout thrash (~110ms): Decoding uncached images synchronously during the first SwiftUI list pass.

Total perceived load hovered around 760ms–900ms—slow enough to break the illusion of a native iOS tool.

Preloading & Warm Caching Architecture

To eliminate perceived latency without complicating our PostgreSQL schema, we reorganized reads around three rules:

  1. Render from a warm disk snapshot on frame zero. On launch, SwiftUI binds immediately to the last serialized collection snapshot while a background task revalidates against Supabase using an updated_at watermark.
  2. Preload likely next transitions. When a user scrolls past a pile card or pauses for 120ms, a low-priority Task warms the top N item payloads and normalized thumbnails into an in-memory LRU cache.
  3. Coalesce metadata on write. Instead of scraping OpenGraph tags on read, our backend extracts and stores compact metadata columns directly in PostgreSQL at save time, turning multi-hop fetches into a single indexed query.
actor WarmPileCache {
    private var memory: [UUID: CachedPile] = [:]

    func fetchOrWarm(id: UUID, loader: @Sendable () async throws -> CachedPile) async throws -> CachedPile {
        if let hit = memory[id], !hit.isStale {
            return hit
        }
        let fresh = try await loader()
        memory[id] = fresh
        return fresh
    }
}

Results

Moving work off the tap critical path cut perceived load latency by 300%—bringing warm transitions under ~200ms while keeping database read volume flat via watermarked delta queries. Fast software rarely requires exotic infrastructure; it mostly requires refusing to wait sequentially for things you already knew the user would tap next.