Remove System.Linq.Expressions usages in ReflectionClrPropertyInfo #16568
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?
This PR removes the
System.Linq.Expressions
usages inReflectionClrPropertyInfo
by using standard reflection instead.With NativeAOT on win-x64, this removes 446 KB of native code.
Rationale
Expressions were probably used for performance in the past for standard property accesses, but it turns out this class is almost unused nowadays.
The only code path creating a
ReflectionClrPropertyInfo
is inStaticResourceExtension
:Avalonia/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
Line 38 in b1489aa
This is never hit by the XamlCompiler, which provides a
ClrPropertyInfo
directly ifStaticResource
is used on a standard CLR property. The only way to get through this is to pass aSystem.Reflection.PropertyInfo
manually toStaticResourceExtension.ProvideValue
.Plus, expressions are interpreted on platform where dynamic code isn't allowed, making them slower than standard reflection in this case.