Make MarkupExtension.ProvideValue method inlinable for StaticResourceExtension and ResolveByNameExtension #17659
+18
−12
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.
What does the pull request do?
There is no XAML magic in this PR, just making extensions implementation easier to digest for JIT compiler.
With .NET 9 optimizations, extension object allocation can be eliminated, if it's simple enough for JIT compiler.
I was able to confirm it with Disasmo #17622 (comment)
These changes didn't really improve our existing benchmarks to a measurable degree. Likely because we lazily evaluate most of static resources in our themes.
What is the current behavior?
{StaticResource}
object can't be inlined by JIT.What is the updated/expected behavior with this PR?
{StaticResource}
object can be inlined by JIT.How was the solution implemented (if it's not obvious)?
Moves complex implementation details to a static stateless method, which we forcefully don't inline. Making instance extension method as simple, as possible (just a simple single
call
), allowing JIT to eliminate instance object creation completely.Note: this improvement is in effect only with .NET 9 target.
Example of affected code:
And generated assembly code (.NET 9). Left 11.2.2, right this PR.
Notable changes:
const string key
(0xD1FFAB1E) was assigned during object creation, afterconst string key
is directly passed to the static method as a parameter.