-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Can we improve ROS<byte>.ToArray from RVA static? #68103
Comments
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsWhen doing using System;
public class C
{
public byte[] Implicit() => new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
public byte[] Explicit() => ((ReadOnlySpan<byte>)new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }).ToArray();
}
|
If understand this correctly you mean that: Trees after Morph - Global
|
Yes, except its not actually an array, so not that it would return the original object but rather directly copy the rva static data as happens in the RuntimeHelpers.InitializeArray Implicit case. I'm asking because if the natural type of the new u8 literal in C# becomes |
I see. Honestly speaking I'd rather optimize this pattern in Roslyn or ILLink substep 🙁 I don't see an easy way to do it in JIT, perhaps someone from @dotnet/jit-contrib does? |
That's fair. |
Roslyn previewed this feature with |
In the prototype the natural type is actually byte[].
Each rune is 32 bits and would negate many of the intended uses of having cheap, direct access to UTF-8 bytes. Or did you mean as an additional target type rather than instead of? |
Ah, u32. Yes there will be a lot of overhead. Way too expensive than multi-byte characters directly encoded to byte array. 😁 I was originally thinking |
It does look nice and optimizable after assertion prop: N007 ( 18, 20) [000141] --CXG------- ▌ CALL void System.Buffer.Memmove $VN.Void
N004 ( 1, 1) [000124] ------------ arg0 in rcx ├──▌ LCL_VAR byref V06 tmp5 u:2 (last use) $280
N005 ( 2, 10) [000190] H----------- arg1 in rdx ├──▌ CNS_INT(h) long 0x142d5bf20a0 static $140
N006 ( 1, 1) [000191] ------------ arg2 in r8 └──▌ CNS_INT long 16 $81 But doing a second pass of morph-like optimizations here would be new territory. |
Ah, indeed, I didn't think of it this way, nice! |
closed via #83638 |
When doing
new byte[] { const, const, const, ... }
, the JIT generates code that calls the new array helper and then emits an unrolled loop to copy the data into the array. When doing((ReadOnlySpan<byte>)new byte[] { const, const, const, ... }).ToArray()
, the copy is handled viaToArray
's call to Buffer.MemMove. Is it feasible to do better?SharpLab
category:cq
theme:optimization
skill-level:beginner
cost:small
impact:small
The text was updated successfully, but these errors were encountered: