Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP apps freeze for few seconds when system theme/accent color changes #3536

Closed
FrayxRulez opened this issue Nov 2, 2020 · 32 comments · Fixed by #3569
Closed

UWP apps freeze for few seconds when system theme/accent color changes #3536

FrayxRulez opened this issue Nov 2, 2020 · 32 comments · Fixed by #3569
Assignees
Labels
area-External Not owned by the WinUI team, not actionable in this repository. no-issue-activity

Comments

@FrayxRulez
Copy link

Describe the bug
All UWP apps seem to be affected by this bug, some of them less (I guess simpler UI tree) and some more.
Whenever the system theme changes, the apps will freeze for few seconds (1-5?).
Something interesting that we found out while researching about this behavior:

  • The freeze affects the app in any case, even if it explicitly sets a RequestedTheme in App.
  • Resizing the app window while it is frozen seems to restore the app usability.
  • Changing RequestedTheme from code behind is instant, and it works so nicely that I've added animations for that:
    transition

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Go to System settings > Personalization > Colors
  2. Change theme or accent color
  3. Try to interact with a UWP app, Settings included.

Expected behavior

The app won't freeze, and the user can continue to interact with it. This is specially important if they have automatic theme/accent color switch based on current system wallpaper, and they have a wallpaper playlist enabled.

Screenshots

Version Info

Windows 10 version Saw the problem?
Insider Build (xxxxx) Yes
May 2020 Update (19041) Yes
November 2019 Update (18363) Yes
May 2019 Update (18362) Yes
October 2018 Update (17763) Yes
April 2018 Update (17134) Yes
Fall Creators Update (16299) Yes
Creators Update (15063) Yes
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 2, 2020
@StephenLPeters StephenLPeters added the area-External Not owned by the WinUI team, not actionable in this repository. label Nov 3, 2020
@StephenLPeters
Copy link
Contributor

I don't think this is a winui issue, its a system/uwp issue. @MikeHillberg or @jevansaks do you think there is anything we can do from our side?

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Nov 3, 2020
@jevansaks
Copy link
Member

Someone would need to debug it. I recommend a WPA trace with CPU Precise events (with call stacks) to see what's causing the app to wake when it finally unblocks (which would tell us what the app is getting stuck on).

I'll take a trace now and see if anything jumps out at me.

@jevansaks jevansaks self-assigned this Nov 3, 2020
@jevansaks
Copy link
Member

I got a trace of the Alarms app running the stopwatch where I did a theme change and I saw that the stopwatch stopped updating for ~2 seconds so that showed that the UI thread was freezing in this scenario. In WPA's CPU Precise view I see no activity for 2 seconds:

image

So I look in there for the ready thread stacks and I see most of them being awoken here:

  Microsoft.UI.Xaml.dll!AcrylicBrush::OnConnected
  Microsoft.UI.Xaml.dll!MaterialHelper::IsFullScreenOrTabletMode
  Microsoft.UI.Xaml.dll!winrt::impl::consume_Windows_UI_ViewManagement_IApplicationView3<winrt::Windows::UI::ViewManagement::ApplicationView>::IsFullScreenMode
  twinapi.appcore.dll!CApplicationView::get_IsFullScreenMode

I wonder if it's possible to avoid Acrylic calling this IsFullScreenMode API during theme change, it seems like this API requires a synchronous call into explorer.exe and explorer.exe gets blocked a lot during theme change so that's going to cause our call to get blocked.

@jevansaks
Copy link
Member

Oh ... hmm ... so it's because we're switching AcrylicBrush instances between Light and Dark theme which is causing the OnConnected call to be made and the AcrylicBrush needs to discover that state from scratch. But I still think we can probably watch for and cache the IsFullScreenMode flag in MaterialHelper instead of calling it each time an AcrylicBrush gets connected for the first time.

@FrayxRulez
Copy link
Author

Hi @jevansaks, thanks for looking into this!
Actually I'm not sure that AcrylicBrush is the only problem, as my app hangs as well, but it doesn't use AcrylicBrush anywhere, and I think that if there isn't any of them in the UI tree OnConnected shouldn't get invoked?

@jevansaks
Copy link
Member

Is your app one that I can install myself? Can you share it?

@FrayxRulez
Copy link
Author

@jevansaks
Copy link
Member

@FrayxRulez I don't have a Telegram login ... is there a way to skip it and still see your main UI with the theme change animation?

@FrayxRulez
Copy link
Author

Currently it is possible to switch to test servers only after the first login, but if you need so, I can add a toggle to switch earlier.

@FrayxRulez
Copy link
Author

Hi @jevansaks, if you update to version 5741 you can login this way:

  • Click 10 times in the app version at the bottom of login screen
  • Switch "Use Test DC" toggle on.
  • Restart the app.
  • Use +9996634567 as phone number and 33333 as security code.

@jevansaks
Copy link
Member

Thanks, @FrayxRulez ! Actually the background of NavigationView's pane is Acrylic. I confirmed that it's there by setting a breakpoint on MIcrosoft.UI.Xaml!AcrylicBrush::OnConnected and seeing that it fires on theme change, so I suspect my fix will help you too.

@FrayxRulez
Copy link
Author

... I'm sorry, being it collapsed most of the time I completely forgot about it.
Thank you for investigating, I hope to see an improvement indeed!

@jevansaks
Copy link
Member

I confirmed that my change fixes the issue for Alarms so can you try out the latest CI build? Here's the nupkg from the CI: https://dev.azure.com/ms/_apis/resources/Containers/7941289/drop?itemPath=drop%2FMicrosoft.UI.Xaml.2.5.0-ci.201109002.nupkg

@FrayxRulez
Copy link
Author

FrayxRulez commented Nov 11, 2020

It seems that I'm not authorized to access the page
Edit: got it :)

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 11, 2020
@FrayxRulez
Copy link
Author

Actually, I just tried and I see absolutely no difference using debug configuration :(

@jevansaks
Copy link
Member

Thanks for trying it! Would you be able to share out (just attached to the comment in github) the appx for me to side-load? Or if you don't want to share broadly, you can email me or DM me on Twitter.

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Nov 12, 2020
@FrayxRulez
Copy link
Author

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 12, 2020
@StephenLPeters StephenLPeters added needs-assignee-attention Assignee needs to follow-up or investigate this issue and removed needs-triage Issue needs to be triaged by the area owners labels Nov 14, 2020
@jevansaks
Copy link
Member

@FrayxRulez I'll also need the public key cert it was signed with, I can't install that bundle without it!

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 14, 2020
@jevansaks
Copy link
Member

Thanks, that made it work. So on my machine this makes the theme change instantaneous (once your app gets the notification), whereas before I was seeing the Unigram app get the theme change notification but then be blocked. I don't see the app freeze anymore. But I do notice that each window seems to change one at a time, so I wonder if the problem is that on your machine there's an app that's running that is blocking the notification from getting to your window right away? Try closing all other apps and see if that helps? (Or run in Windows Sandbox)

unigramtheme

@StephenLPeters StephenLPeters added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Nov 17, 2020
@jevansaks jevansaks removed the needs-assignee-attention Assignee needs to follow-up or investigate this issue label Nov 18, 2020
@FrayxRulez
Copy link
Author

Hi @jevansaks sorry for the late reply.
Yeah, you're right, theme switches immediately now, but still the window is frozen for ~4 seconds after the theme change.
I guess that this doesn't depend on WinUI, but maybe this can be reported to the right team?

@ghost ghost added needs-assignee-attention Assignee needs to follow-up or investigate this issue needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Nov 18, 2020
@jevansaks
Copy link
Member

What do you mean by "frozen"? Like you can't move the window or you can't click inside it or what?

@ranjeshj ranjeshj added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners needs-assignee-attention Assignee needs to follow-up or investigate this issue labels Nov 19, 2020
@FrayxRulez
Copy link
Author

All of them so far, I get west-est resize cursor and clicks get processed after the freeze

@ghost ghost added needs-assignee-attention Assignee needs to follow-up or investigate this issue needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Nov 19, 2020
@jevansaks
Copy link
Member

I'm about to go on vacation so I won't have time to help on this for at least a couple of weeks. Anyone else should be able to do the same kind of investigation I did (see above comment about using WPR to record the scenario and WPA to investigate). Use the CPU Precise view and filter to your process. The "ready thread" stack after the app unfreezes will tell you where it was stuck before that.

@jevansaks jevansaks removed the needs-assignee-attention Assignee needs to follow-up or investigate this issue label Nov 19, 2020
@StephenLPeters StephenLPeters assigned ranjeshj and unassigned jevansaks Nov 20, 2020
@ranjeshj ranjeshj removed the needs-triage Issue needs to be triaged by the area owners label Nov 24, 2020
@riverar
Copy link
Contributor

riverar commented May 31, 2021

This repros everywhere, even in a vm, and is well known, so not sure why you need traces from us?

@jevansaks
Copy link
Member

jevansaks commented Jun 1, 2021

This repros everywhere, even in a vm, and is well known, so not sure why you need traces from us?

@riverar Are you talking about (1) a specific app with a dynamic setting to change its own theme hanging or (2) are you talking about the whole system hanging when you change the theme in Settings?

If (1), the only issue I saw was the one I fixed. If (2), please file an issue in Feedback Hub since that's an OS issue and not a WinUI one.

@riverar
Copy link
Contributor

riverar commented Jun 1, 2021

@jevansaks Windows 10 grinds to a halt when changing theme. I suspect that's the underlying issue that @FrayxRulez is referring to here. Agree though, this is more of an OS issue than anything MUX related.

It's not very productive to even talk about theme change performance relative to the app when the entire system is locked up.

@jevansaks
Copy link
Member

I think we got distracted by the discussion in this thread about the hang that repros when the app changes its own theme. We addressed that. But the remaining issue needs to be filed as a Feedback Hub report.

@riverar can you do that and link the feedback URL? I will help it find the right home.

@mkielar
Copy link

mkielar commented Sep 6, 2022

I'm seeing this behavior on Windows 11 Pro / 21H2 / 22000.856.

I had a background slideshow enabled with images switched every 1 minute. I also had "Accent color" set to "Automatic", and both "Show accent color on Start and taskbar" and "Show accent color on title bars and windows borders" enabled. What happened, is, every minute, following happened:

  1. The entire system would start lagging for 2-5 seconds
  2. During that time, taskbar icons would visibly blink several times - like they're being redrawn several times.
  3. During that time, the keyboard input lagged visibly. If I was typing anything, the text buffered and only appeared on screen after the lagging was over (2-5 seconds later)
  4. If I also moved a mouse during that time, the cursor would also lag visibly, and if the mouse movement was intense, the system would issue a "beep" (or sometimes several "beeps").

This is on brand new DELL XPS 19 9520 running 12th Gen Intel(R) Core(TM) i9-12900HK. Neither Windows Update not Dell Command showed any updates pending, from I'm assuming I had everything "latest".

The issue stopped appearing after I switched the "Accent color" setting to "Manual" and turned off "Show accent color on Start and taskbar" and "Show accent color on title bars and windows borders".

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-External Not owned by the WinUI team, not actionable in this repository. no-issue-activity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants