Skip to content
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

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

Closed
EgorBo opened this issue Sep 10, 2020 · 5 comments · Fixed by #77593
Closed

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

EgorBo opened this issue Sep 10, 2020 · 5 comments · Fixed by #77593
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI tenet-performance Performance related issue
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Sep 10, 2020

#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

@EgorBo EgorBo added the tenet-performance Performance related issue label Sep 10, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Sep 10, 2020
@am11
Copy link
Member

am11 commented Sep 10, 2020

@EgorBo, would it happen on post-materialization phase and would it also cover tricky cases like someone is using reflection to update the value of static readonly field?

@MichalStrehovsky
Copy link
Member

using reflection to update the value of static readonly field?

Reflection stack disallows this because there's existing codegen optimizations that rely on them being immutable. One can still break this (because nothing prevents e.g. re-running the static constructor and depending on what the static constructor does we might end up with a different value), but those are mostly academic scenarios.

@JulieLeeMSFT JulieLeeMSFT added this to the Future milestone Sep 11, 2020
@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Sep 11, 2020
@GSPP
Copy link

GSPP commented Sep 20, 2020

Maybe it should be prevented to re-run the static constructor.

@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@BruceForstall BruceForstall removed the JitUntriaged CLR JIT issues needing additional triage label Nov 7, 2020
@BrianBohe BrianBohe self-assigned this Oct 14, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 28, 2022
@EgorBo
Copy link
Member Author

EgorBo commented Oct 28, 2022

@BrianBohe oops, didn't notice you self assigned this, I filed a PR that fixed a different thing but as a side effect it fixes this too

@EgorBo EgorBo modified the milestones: Future, 8.0.0 Oct 28, 2022
@EgorBo EgorBo assigned EgorBo and unassigned BrianBohe Oct 28, 2022
@BrianBohe
Copy link
Member

@BrianBohe oops, didn't notice you self assigned this, I filed a PR that fixed a different thing but as a side effect it fixes this too

It's okay don't worry. I assigned it to me but I wasn't able to start it.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants