You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Escape Analysis: Elide an array allocation in BitConverter.GetBytes pattern #113236
This pattern could be used as a safe alternative to "write N-bytes of a primitive to a span of bytes". Alternative zero-alloc patterns don't look pretty/involve unsafe
Inline candidate has an arg that feeds a constant test. Multiplier increased to 1.
Inline candidate callsite is boring. Multiplier increased to 2.3.
calleeNativeSizeEstimate=461
callsiteNativeSizeEstimate=135
benefit multiplier=2.3
threshold=310
Native estimate for function size exceeds threshold for inlining 46.1 > 31 (multiplier = 2.3)
Inline expansion aborted, inline not profitable
Inlining [000020] failed, so bashing STMT00008 to NOP
INLINER: during 'fgInline' result 'failed this call site' reason 'unprofitable inline' for 'Program:<<Main>$>g__Test|0_0(int,System.Span`1[ubyte])' calling 'System.BitConverter:TryWriteBytes(System.Span`1[ubyte],int):ubyte'
INLINER: during 'fgInline' result 'failed this call site' reason 'unprofitable inline'
JIT evaluation
1 arguments are structs passed by value. Multiplier increased to 2.
Inline has 2 intrinsics. Multiplier increased to 3.6.
Inline candidate has 1 binary expressions with constants. Multiplier increased to 4.1.
Inline candidate callsite is boring. Multiplier increased to 5.4.
calleeNativeSizeEstimate=461
callsiteNativeSizeEstimate=135
benefit multiplier=5.4
threshold=728
Native estimate for function size is within threshold for inlining 46.1 <= 72.8 (multiplier = 5.4)
For R2R inlining doesn't happen unless there is static PGO data (I think, a little tricky to verify right now)... the "returns new array" heuristic requires the extended default policy.
I don't think we're going to get this working in .NET 10.
We need to land #116651, which is held up because we generally can't embed array class handles in R2R.
We need to figure out a proper inlining boost for TryWriteBytes, but a broad boost seems risky. I am seeing perf issues with more inlining in R2R, which will plague us until we can sort out Support profile instrumentation for inlinees #44372. And a targeted boost may not be that great either (say aggressive inlining) as there methods for each different primitive data type.
I'm going to move this to future... if we manage to merge #116651 maybe we can take another look.
Activity
dotnet-policy-service commentedon Mar 6, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndyAyersMS commentedon Mar 6, 2025
Looks like my upcoming escape analysis changes will indeed stack allocate here...
JIT: enhance escape analysis to understand local struct fields
JIT: enhance escape analysis to understand local struct fields
JIT: enhance escape analysis to understand local struct fields (dotne…
3 remaining items
AndyAyersMS commentedon Apr 16, 2025
So, good news and not so good news. If I forcibly inline we end up with code like the below.
No stack allocation, but we create a bunch of messes we really ought to be able to clean up.
EgorBo commentedon Apr 16, 2025
@AndyAyersMS perhaps, the codegen is a lot better in Release version of corelib? since yours is Checked with asserts
AndyAyersMS commentedon Apr 16, 2025
Could be... will need to do a proper check since the config I used to alter inlining doesn't work in release.
Oddly if I use
DOTNET_JitAggressiveInlining=1(which works in release) we think the array escapes. So will need to look into that too.AndyAyersMS commentedon Apr 17, 2025
Ok with #114749 and a targeted inlining hint we have
Still a bit messy, but better than what I showed above.
Seems like we might want to boost inlining for methods that
AndyAyersMS commentedon Apr 17, 2025
R2R doesn't inline TryWriteBytes
R2R evaluation
JIT evaluation
If I unblock that, we don't stack allocate:
JIT: boost inlining for methods that may return small arrays
JIT: boost inlining for methods that may return small arrays (#114806)
AndyAyersMS commentedon Apr 28, 2025
Current codegen (both TC=0 and PGO):
AndyAyersMS commentedon Apr 28, 2025
For R2R inlining doesn't happen unless there is static PGO data (I think, a little tricky to verify right now)... the "returns new array" heuristic requires the extended default policy.
JIT: enable stack allocation of more arrays in R2R
AndyAyersMS commentedon Jul 9, 2025
I don't think we're going to get this working in .NET 10.
TryWriteBytes, but a broad boost seems risky. I am seeing perf issues with more inlining in R2R, which will plague us until we can sort out Support profile instrumentation for inlinees #44372. And a targeted boost may not be that great either (say aggressive inlining) as there methods for each different primitive data type.I'm going to move this to future... if we manage to merge #116651 maybe we can take another look.
JIT: enable stack allocation of more arrays in R2R (#116651)