Skip to content

RyuJIT: Extend "cns".Length optimization to support static readonly fields #42087

@EgorBo

Description

@EgorBo

#1378 introduced an optimization to fold "const str".Length into a const int. It probably makes sense to extend it to also support static readonly string fields, e.g:

image

Prototype: master...EgorBo:static-readonly-string-fields-opts
(it extends the existing jit-vm API getStringLiteral to accept a field reference).

jit-diff (--pmi --cctors) is not as exciting as I hoped:

(Lower is better)
Total bytes of diff: -242 (-0.00% of base)
    diff is an improvement.
Top file improvements (bytes):
        -143 : System.Diagnostics.DiagnosticSource.dasm (-0.18% of base)
         -83 : Microsoft.CodeAnalysis.dasm (-0.00% of base)
         -16 : xunit.execution.dotnet.dasm (-0.01% of base)
3 total files with Code Size differences (3 improved, 0 regressed), 264 unchanged.
Top method improvements (bytes):
        -143 (-29.12% of base) : System.Diagnostics.DiagnosticSource.dasm - Activity:GenerateRootId():String
         -71 (-18.68% of base) : Microsoft.CodeAnalysis.dasm - Reader:Read(ref,int,int):int:this
         -16 (-5.42% of base) : xunit.execution.dotnet.dasm - SerializationHelper:GetType(String,String):Type
         -12 (-26.67% of base) : Microsoft.CodeAnalysis.dasm - Reader:SetText(String):this
Top method improvements (percentages):
        -143 (-29.12% of base) : System.Diagnostics.DiagnosticSource.dasm - Activity:GenerateRootId():String
         -12 (-26.67% of base) : Microsoft.CodeAnalysis.dasm - Reader:SetText(String):this
         -71 (-18.68% of base) : Microsoft.CodeAnalysis.dasm - Reader:Read(ref,int,int):int:this
         -16 (-5.42% of base) : xunit.execution.dotnet.dasm - SerializationHelper:GetType(String,String):Type
4 total methods with Code Size differences (4 improved, 0 regressed), 258661 unchanged.
Completed analysis in 18.54s

so feel free to close it if you think it's not worth the effort.

category:cq
theme:basic-cq
skill-level:beginner
cost:small

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions