Scale Image Work Down When Your App Runs Hot

An image browser feels fine at launch and becomes sluggish after several minutes of scrolling and editing. A fixed concurrency limit may be reasonable when the device is cool and too aggressive when the system is already under thermal pressure.

Use thermal state to adjust optional preview work. Keep the original document and explicit export settings outside that preview-quality policy.

Turn thermal state into a budget

ProcessInfo reports nominal, fair, serious, and critical thermal states. Here is an intentionally simple starting policy:

import Foundation

struct ImageBudget: Equatable {
    let concurrentPreviews: Int
    let previewPixelLimit: Int
}
func imageBudget(for state: ProcessInfo.ThermalState) -> ImageBudget {
    switch state {
    case .nominal: return ImageBudget(concurrentPreviews: 3, previewPixelLimit: 960)
    case .fair: return ImageBudget(concurrentPreviews: 2, previewPixelLimit: 768)
    case .serious: return ImageBudget(concurrentPreviews: 1, previewPixelLimit: 480)
    case .critical: return ImageBudget(concurrentPreviews: 0, previewPixelLimit: 480)
    @unknown default: return ImageBudget(concurrentPreviews: 1, previewPixelLimit: 480)
    }
}
struct PreviewAdmission {
    private(set) var active = 0
    var budget: ImageBudget
    mutating func begin() -> Bool {
        guard active < budget.concurrentPreviews else { return false }
        active += 1
        return true
    }
    mutating func finish() {
        precondition(active > 0)
        active -= 1
    }
}

These concurrency and pixel values are illustrative application choices, not Apple-recommended constants. Pick real limits from your workload and device measurements.

At critical state, Apple recommends reducing CPU, GPU, and I/O activity to the minimum needed for interaction. This policy admits no new optional previews. Existing cached content can keep the browser useful while the device cools.

Shrink admission without rewriting history

Imagine three previews are running when the budget drops to one. Setting active = 1 would make the counter inaccurate. Cancelling all three is not necessarily immediate either; some synchronous decode work cannot stop halfway through a function call.

The admission structure leaves the active count at three. As jobs finish, the queue refuses replacements until activity falls below the new limit. Every successful begin must have exactly one matching finish, including errors and cancellation.

Keep this state on one actor or another serialized owner. The struct is a policy example, not a thread-safe queue by itself. Also retain jobs in a bounded queue rather than creating one suspended Task for every image and hoping the counter limits all resource use.

Capture a size for each admitted job

When admitting a preview, pass that budget’s pixel limit into the decoder. Our bounded thumbnail example shows how to downsample from an encoded file before retaining a full-resolution bitmap.

A smaller decode target reduces the preview’s pixel workload. It does not justify modifying the original image or changing an export the user requested at a particular quality.

Include the requested size in the cache key, or otherwise track the quality of the cached result. A 480-pixel thermal fallback should not permanently satisfy a later 960-pixel request just because the source URL matches.

Do not invalidate every cached image when the thermal state changes. Keep usable content on screen and upgrade only when the larger result becomes useful and the budget permits it.

Observe changes, then query current state

Install the thermal-state observation in the workload coordinator and read ProcessInfo.processInfo.thermalState when it changes. Take an initial reading too. Treat notifications as a reason to refresh policy, not as a temperature history or an instruction to toggle between two modes.

For a workload that oscillates rapidly, consider a conservative recovery delay before increasing work again. That hysteresis is an application policy to measure, not a reason to poll thermal state constantly.

Test the queue’s invariant

The fixture admits three nominal-state jobs, lowers the budget to one, and verifies that replacement work stays blocked while the old jobs drain. It then verifies critical-state admission stops and fair-state recovery admits work again.

That sequence is more useful than only asserting that .serious maps to the number one. It catches the accounting bug that appears during a real transition.

On hardware, measure interaction latency, memory, and energy with a representative library and sustained use. Thermal state describes system conditions, not which one of your functions caused them. Do not infer a temperature or battery-saving percentage from this enum.

September 2026 review: budget and draining assertions passed with Swift 6.4, and the ProcessInfo types checked for iOS 17. The numeric policy has not been tuned or benchmarked on a physical device.