fix(apple): Load NSImage in MenuBar asynchronously#8090
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Sentry Issue: APPLE-CLIENT-10 |
jamilbk
commented
Feb 11, 2025
| extension MenuBar: NSMenuDelegate { | ||
| } | ||
|
|
||
| extension NSImage { |
ef95eed to
36796a4
Compare
thomaseizinger
approved these changes
Feb 11, 2025
Member
thomaseizinger
left a comment
There was a problem hiding this comment.
Our tiny icons can cause a hang? That seems quite unlikely. We'll see if this fixes things though.
|
Sentry Issue: APPLE-CLIENT-20 |
|
Sentry Issue: APPLE-CLIENT-22 |
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Feb 20, 2025
Loading images async isn't fixing the App Hanging reports we continue to receive, so it's something else. Rather than trying to load them asynchronously, we revert that change. We instead eager-load all images needed by the MenuBar at init instead of lazy-loading them, which in rare cases could cause apparent UI hangs. If we can't load them we log an error but continue to try an operate, as the icons are not strictly needed for Firezone operation. Reverts #8090
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After further investigation, it appears that the
NSImageinitializer loads and decodes images synchronously from the disk. In the MenuBar, we are "lazy-loading" these images, but since the menu is constructed as part of app initialization, we are effectively loading these when the app boots, inFirezoneApp.After loading, these are cached, but the initial can hang the UI thread on app launch for slow systems.
Unfortunately,
NSImagedoes not formally conform to@Sendable. However, this may be a nuance that isn't true in most cases, such as when treatingNSImageinstances as read-only from only a single thread.As such, we wrap
NSImagewith our own struct, and mark it@unchecked Sendable. This allows us to load the images on a background thread and assign them to their UI thread counterparts in an async manner.See further discussion:
Related: #7771