Skip to content

Fix app unresponsive when loading images#163

Open
isaac-weisberg wants to merge 2 commits into
gro-ove:masterfrom
isaac-weisberg:isaac/fix-blocked-ui
Open

Fix app unresponsive when loading images#163
isaac-weisberg wants to merge 2 commits into
gro-ove:masterfrom
isaac-weisberg:isaac/fix-blocked-ui

Conversation

@isaac-weisberg
Copy link
Copy Markdown

@isaac-weisberg isaac-weisberg commented May 23, 2026

Right now there are several cases in the launcher where the app becomes unresponsive:

  • selecting a server
  • opening Media page for the first time
  • opening Results page for the first time
  • randomly when scrolling around in the cars list

I have profiled the application in Visual Studio, and I have found out that most of the CPU time of the program has been taken by BetterImage.cs calling BitmapImage.EndInit()

BetterImage.cs tries to decode images less than 50 KB synchronously on the UI thread, however what happens is that BitmapImage.EndInit() underneath calls FinalizeCreation(), which inside has logic that causes the color profile of the source image to be converted via a call to new ColorConvertedBitmap which under the hood calls UnsafeNativeMethods.WICColorTransform.Initialize, which is implemented by a blocking interop service call. This procedure ends up being very slow, and because it's on main thread, this causes UI to stutter.

endinit perf

My proposed solution is to reduce altogether the work needed by disabling the color profile conversion via providing CreateOptions = BitmapCreateOptions.IgnoreColorProfile.

This has caused some images to cause an exception in the BetterImage.cs automatic cropping functionality available via DependencyProperty CropTransparentAreas. There was an invalid assumption of what the characteristics of an image were supposed to be in order to fit into a fixed size array. I have fixed it by checking directly against the size of the buffer rather than the width and stride values.

After the fix, the navigation in the app is instantaneous, there is no more unresponsiveness. Profiling after the fix shows drastic fall in CPU usage and the Hot Path is now nothing significant.

Before the fix:

CPU usage before

After the fix:

profile after fix

Video:

Before:

before.720.mov

After:

after.720.mov

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.

1 participant