-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve performance of DynamicResource usages #5610
Conversation
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs
Outdated
Show resolved
Hide resolved
@dotnet/wpf-developers any news on this one? |
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs
Outdated
Show resolved
Hide resolved
4aa6c7c
to
d53d56c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you thought about how it can be tested? How did you confirm the performance is improved?
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs
Outdated
Show resolved
Hide resolved
I asked about how we are expected to write tests in multiple of my PRs, but never got an answer... Performance improvements were checked by testing the app from #4468. |
d53d56c
to
fc8f172
Compare
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResources.cs
Outdated
Show resolved
Hide resolved
fc8f172
to
e0ed241
Compare
Thanks @batzen ! |
@batzen Contratulations, you finally got it! 😉👍🏼🍾 |
In which release can we expect this fix? |
@znakeeye I think it will enter .NET 9. |
@batzen, we have encountered a regression due to these changes. As it turns out, we are not expecting a Please find the sample repro here. Try running the |
@harshit7962 Will have a look as soon as i can. |
Created PR #9393 to fix the issues |
@batzen, thank for your fix earlier, but even with the fix we are yet to close a few regression issues that we got to know of recently. I have created a sample repro here. The application is expected to crash with preview 7 (or rc1) binaries of .NET 9. Apologies for this iterative reporting, hopefully we will be closing these in a single go this time. |
@harshit7962 The first error i encounter is an exception because a This was also an error before my changes, but the exception was thrown at a different point in time. Before my changes the exception was thrown during rendering, caught there and the program just continued:
After my changes the exception is thrown during BAML processing:
|
@batzen Agreed that the exception being thrown is the correct way, however this creates a compat problem for applications that currently use |
This reverts commit 38a157c.
Can someone clarify what the migration expectations to newer versions of WPF are in general? Why are we expecting .NET Core 3 apps to run on .NET 9 without any change? Apps that cannot update to .NET 9 without recompilation can stay on .NET 8, that's why we have runtime config to specify which runtime should be used. |
I agree with @miloush here as I've been asking myself the same question. This issue is also the prime example, essentially having a bug in your code that didn't only cause a crash thanks to the exception being swallowed. It just makes no sense in my opinion. And there's a history of such changes happening from version to version outside WPF, don't see why it should be any different when it's a step in the right direction. |
@batzen, we are trying to evaluate the regression radius of the changes at the moment. I have created a minimal repro of the above application here. The following is my findings as of now. The crash is reported only when we include the following in our csproj. <ItemGroup>
<Resource Include="ButtonStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup> Need your help in understanding this change in behavior. Tagging @miloush and @h3xds1nz for their feedbacks and opinions. |
Is this only XAML parsing issue or runtime too? (Since it's a dynamic resource, a wrong type can be provided at runtime. If that now crashes and didn't used to, it would be even more concerning than the XAML parsing which is apparent immediately) |
What I fail to understand in detail because I can't debug the previous version today is how did this change happened but I can imagine that the value was already |
I agree that these are errors in the applications and not WPF, and I fully support the early, compile-time failure. However, already during one preview release there is evidence this change breaks things - and that doesn't happen very often, it is the reason why preview releases exist in the first place. It is also very late in the release cycle and I doubt any further changes to the codebase will be entertained for 9 without giving people an opportunity to test them. I wonder whether we could have it failing compilation forward but not crash applications if they run on a newer runtime than they have been compiled with? |
Control the behaviour with a feature switch. |
Switch is my least favorite option, we keep piling (often unnecessary) switches and never remove them. I am also not quite sure how switch would achieve a feature to be available at compile time but not at runtime (and there might be not enough time to test the switch before RTM). I believe the agreement is we do want the changes in this PR to be part of the product and if the intent is to update the PR to avoid breaking these apps without a switch, then the PR can be updated and merged back later, unless there is an urgency that I missed. (On the other hand you could say setting a .NET runtime version in the config is a switch.) |
Feature switches are used at runtime. |
You can learn more at https://learn.microsoft.com/dotnet/core/runtime-config/. |
@h3xds1nz, regarding this, I would like to clarify the exact scenario. The application will not crash in .NET 8, if we do not include the brush Instead if it is referenced from a resource dictionary not directly included with our application. In the repro, it is included via the Since the above mentioned dictionary is not available in .NET 8, I have tweaked the above repro to load the The mentioned behavior is present in the application here. The application is expected to launch in .NET 8 and crash with |
Sorry, it was a direct reply to miloush's question, when you try to set an invalid resource reference type during runtime on |
Actually, we would like to avoid breaking people as much as possible. And the places we would like to break are the ones that have good risk v/s rewards ratio. Given the current state where applications having incorrect We absolutely love this change, and we don't want to defer this change for next .NET release. As a stop-gap measure, we would be proceeding with adding an opt-out switch for .NET 9 release only. We realize this is not ideal and having an opt-out for every single feature is certainly not the way we want our product to evolve. However, we are currently very close to release deadline for .NET 9 and I'm afraid that any more behavior changes at this point may create compat problems that we may not have enough time to fix. |
@pchaurasia14 Thank you, being it an opt-out switch for .NET 9 release only is very much an acceptable solution that is consistent with the time constraints for .NET 9 in my opinion. |
Fixes Issue #4468
Description
The currently used implementation to keep track of DynamicResource usages is suboptimal as the list can grow quite large and scanning gets very expensive.
That's caused by two issues:
The improved implementation only adds items with the same key once by checking for existing items before adding new ones. As the new implementation uses keys, retrieval of items is very fast.
Customer Impact
Slow performance.
Testing
Tested the app from #4468