Fix app unresponsive when loading images#163
Open
isaac-weisberg wants to merge 2 commits into
Open
Conversation
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.
Right now there are several cases in the launcher where the app becomes unresponsive:
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 callsFinalizeCreation(), which inside has logic that causes the color profile of the source image to be converted via a call tonew ColorConvertedBitmapwhich under the hood callsUnsafeNativeMethods.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.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:
After the fix:
Video:
Before:
before.720.mov
After:
after.720.mov