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
It seems that _compilation.HasLazyStaticConstructor(field.OwningType) returns true for Program so MyStr field is not pre-computed despite being a simple struct + frozen string literal.
It was a surprise to find that NativeAOT's disassembly is considerably worse than CoreCLR's codegen, which handles frozen string fields much more efficiently. It's one thing for codegen to be imperfect, but this level of inefficiency is quite surprising.
@am11 yep, this issue is exactly what prevents NativeAOT to generate optimimal codegen for RuntimeInformation.IsOSPlatform API. I guess it's not super important because it's a sort of a legacy API (although, still tons of usages).
or is it part of emerging value-type pattern relying on frozen strings in static contexts?
It is an example of code where tiered JITing has an advantage. Code that takes advantages of unique tiered JITing capabilities does not always work in the most optimal way with AOT, and vice versa.
In theory, this example can be fixed in the AOT interpreter. Most readonly statics instances that people expect to be optimized by tiered JIT are not like that.
Activity
MichalStrehovsky commentedon Mar 6, 2023
Value types are represented as byte arrays within the interpreter. It's hard to add object references to it.
The features the interpreter supports follow the pareto principle.
jkotas commentedon Mar 7, 2023
Similar issue for initialization of reference types: #82993
am11 commentedon Apr 8, 2025
It was a surprise to find that NativeAOT's disassembly is considerably worse than CoreCLR's codegen, which handles frozen string fields much more efficiently. It's one thing for codegen to be imperfect, but this level of inefficiency is quite surprising.
EgorBo commentedon Apr 8, 2025
@am11 yep, this issue is exactly what prevents NativeAOT to generate optimimal codegen for
RuntimeInformation.IsOSPlatformAPI. I guess it's not super important because it's a sort of a legacy API (although, still tons of usages).am11 commentedon Apr 8, 2025
@EgorBo, is it just this API, or is it part of emerging value-type pattern relying on frozen strings in static contexts?
EgorBo commentedon Apr 8, 2025
it was not this api specific, I just don't know any other API that could benefit (but currently does not) from this
jkotas commentedon Apr 8, 2025
It is an example of code where tiered JITing has an advantage. Code that takes advantages of unique tiered JITing capabilities does not always work in the most optimal way with AOT, and vice versa.
In theory, this example can be fixed in the AOT interpreter. Most readonly statics instances that people expect to be optimized by tiered JIT are not like that.