-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Windows] Optimize getting default font size and font family values #22782
[Windows] Optimize getting default font size and font family values #22782
Conversation
(Perhaps @Youssef1313 would know if this PR can work given his recent work with |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Hi @MartyIX I don't recall doing stuff related to |
@Youssef1313 Thank you for your reply! Yes, though you filed unoplatform/uno#15437 issue. This PR is actually more related to WinUI than to MAUI. But perhaps I got it wrong. |
@MartyIX Ah, in that case, it's not yet clear to us exactly why inheritance changes don't fire the callback. However, if there is nothing MAUI-specific here, I don't see how these |
Yes, I could not make it fire so I think it's not correct. Would you have an idea of a different approach or how to make this work? I tend to think that what I try to achieve here is not possible (at the moment). |
Yes I don't think WinUI exposes an API to listen for changes in ResourceDictionary. But maybe there could be a way to somehow reduce the number of calls to |
So I found https://github.com/microsoft/microsoft-ui-xaml/blob/2a60e27c591846556fa9ec4d8f305afdf0f96dc1/dxaml/xcp/dxaml/themes/generic.xaml#L14 and https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.fontfamily.xamlautofontfamily?view=winrt-22621. Then one can see many instances of
It's hard to imagine that default font or font size changes with a theme change, so just caching the values once seems easy and correct. Fully correct would be to cache values after theme changes which seems reasonably easy to do as well. Would you agree with the assessment or not? |
@MartyIX I guess users can do something like |
Good point. Given my previous comment, it should not lead to UI changes because WinUI uses The good thing is that I can try this change in a sandbox project to see what would happen. |
cf8ef0a
to
ab8e7da
Compare
I think just caching the value is fine. If this becomes a big issue for people we can either introduce a flag to disable the cache, or revert the PR. But I think 99% of users will benefit from this so we should merge it. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Description of Change
I've been profiling my "complex grid" case again (see #21787) and I noticed that getting
DefaultFontFamily
andDefaultFontSize
is costly on Windows because it requires interop operations on every access ofFontManager.DefaultFontFamily
andFontManager.DefaultFontSize
.Interestingly, on Android it's just a simple constant.
Moreover, on IOS the value is cached.
But on Windows, the values are read over and over again.
There are two paths possible for Windows here:
DefaultFontFamily
andDefaultFontSize
but listen to changes (it appearsContentControlThemeFontFamily
is basically static; see [Windows] Optimize getting default font size and font family values #22782 (comment)).Performance impact
main
: Maui.Controls.Sample.Sandbox.exe_20240602_102503.speedscope.MAIN.json-> ~%79 improvement
Issues Fixed
Contributes to #21787