Skip to content

fix: prevent app hang during image scrim color calculation - #12

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/app-hang-image-scrim
Open

fix: prevent app hang during image scrim color calculation#12
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/app-hang-image-scrim

Conversation

@sentry

@sentry sentry Bot commented Aug 6, 2026

Copy link
Copy Markdown

This PR addresses an app hang issue (OPENNOW-MAC-2Q) caused by synchronous, CPU-intensive image processing on the main thread.

Root Cause:
The loadImage() function, marked @MainActor, was calling CatalogHeroImageMetadata.scrimColor(from:) directly. This function, in turn, performed blocking operations like CGImageSourceCreateWithData, CGImageSourceCreateThumbnailAtIndex, and JSON decoding on the main thread. For larger images, this work could exceed 2000 ms, leading to an app hang.

Solution:

  1. CatalogHeroImageMetadata.scrimColor(from:): Modified this function to be async and nonisolated. The heavy image processing and JSON decoding logic within it is now wrapped in await Task.detached(priority: .userInitiated) { ... }.value. This ensures that all CPU-bound work is executed on a background thread, freeing up the main actor.
  2. loadImage() call site: The call to CatalogHeroImageMetadata.scrimColor(from:) in loadImage() now awaits the async version. This allows the main thread to yield control while the background task completes, preventing UI unresponsiveness. A guard !Task.isCancelled check was added after the await to handle potential task cancellations gracefully.

Impact:
This change significantly improves UI responsiveness when loading catalog hero images by offloading heavy image metadata extraction from the main thread, thereby preventing app hangs.

Fixes OPENNOW-MAC-2Q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants