- Notifications
You must be signed in to change notification settings - Fork5.2k
Expand unboxing for Nullable<> in JIT#105073
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
EgorBo commentedJul 18, 2024
@EgorBot -intel -arm64 usingBenchmarkDotNet.Attributes;publicclassMyBench{[Benchmark][Arguments(42)][Arguments(null)]publicint?Unbox(objecto)=>(int?)o;} |
huoyaoyuan commentedJul 18, 2024
Does it worth to recognize Or, can we write the method in C# and make helpers inlinable? This will help more around nullables. |
EgorBo commentedJul 18, 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.
Yes, that is an option, requires some effort to make helpers inlineable, they're currently not. I decided to do it in JIT since the actual change is like 30 LOC, the rest are comments. If we move it to an inlineable helper we can delete this I guess.. |
EgorBot commentedJul 18, 2024
Benchmark results on Intel
|
EgorBot commentedJul 18, 2024
Benchmark results on Arm64
|
EgorBo commentedJul 18, 2024
EgorBo commentedJul 18, 2024
@jakobbotsch@AndyAyersMS cc @dotnet/jit-contrib PTAL, the actual change is 40 LOC, benchmarks attached. Jit-diff:MihuBot/runtime-utils#541 obviously, a size regression, but there were also a few cases where jit can now fold the |
| // Unbox the object to the result local: | ||
| // | ||
| // result._hasValue = true; | ||
| // result._value = MethodTableLookup(obj); |
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.
oops, wrong comment, it'sobj->RawData
AndyAyersMS left a comment
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.
Would it be worth limiting this to relatively small types, since will create both a zeroing and a copy?
EgorBo commentedJul 18, 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.
Might be a good idea to limit it, yeah @EgorBot -intel -arm64 usingSystem.Runtime.CompilerServices;usingBenchmarkDotNet.Attributes;publicclassMyBench2{[InlineArray(100)]publicstructLargeStruct{publiclongFld;}[Benchmark][Arguments(42)][Arguments(null)]publicLargeStruct?Unbox(objecto)=>(LargeStruct?)o;} |
EgorBot commentedJul 18, 2024
Benchmark results on Intel
|
EgorBo commentedJul 18, 2024
@EgorBot -intel -arm64 usingSystem.Runtime.CompilerServices;usingBenchmarkDotNet.Attributes;publicclassMyBench2{[InlineArray(100)]publicstructLargeStruct{publiclongFld;}publicIEnumerable<object>TestData(){yieldreturnnull;yieldreturnnewLargeStruct();}[Benchmark][ArgumentsSource(nameof(TestData))]publicLargeStruct?Unbox(objecto)=>(LargeStruct?)o;} |
EgorBot commentedJul 18, 2024
Benchmark results on Intel
|
EgorBot commentedJul 18, 2024
Benchmark results on Arm64
|
Uh oh!
There was an error while loading.Please reload this page.
Closes#104954
Currently, unboxing for Nullable<> always go through a helper call, while we can inline it in JIT.
Current codegen:
New codegen:
Benchmark: