- Notifications
You must be signed in to change notification settings - Fork5.1k
Fast FieldInfo reflection#98199
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedFeb 9, 2024
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsVerifying tests
|
6a3ffc9
to081f6b3
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Runtime/tests/System.Reflection.Tests/FieldInfoTests.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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.
JFYI there is anopen question in the PR, otherwise LGTM.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
steveharter commentedFeb 13, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@jkotas I noticed that the runtime wraps exceptions thrown in Unlike invoking a static method, calling GetField\SetField doesn't run any code (fields don't have code) except for the possibility of indirectly calling the class initializer. So unless I hear otherwise, I'll create issue for Mono and NativeAOT to throw UPDATE: there doesn't appear to be hard rules when the class initializer is called other than "when first accessed", so either |
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
This makes
FieldInfo.SetValue
andGetValue
faster; the most improvements are:The cases for setting a value type in a static field are not improved since they follow the existing "slow path" to the runtime due to special logic including "box into" where we box the value type into an existing boxed object (non-primitive static value types are stored that way) and other special logic such as nullability. There are also other "slow paths" for cases where static variables are not fixed in memory, but these are somewhat rare cases.
This was done without using IL-emit; raw memory operations are used. This means there is no warm-up time and works on platforms that do not support emit.
This helps align field performance with fast property performance work (which is IL-emit based) that was done inv7 andv8. For example:
In the future, the "FieldAccessor" class added here can be exposed publicly and methods added that do not require boxing\unboxing.
New benchmarks were added indotnet/performance#3863.
Click for benchmarks
<\details>