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

JIT: optimize redundant Span.Clear #110860

Open
EgorBo opened this issue Dec 20, 2024 · 3 comments
Open

JIT: optimize redundant Span.Clear #110860

EgorBo opened this issue Dec 20, 2024 · 3 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Dec 20, 2024

void Pattern(int len)
{
    Span<byte> span = (uint)len > 1024 ? new byte[len] : stackalloc byte[len];
    span.Clear();
    Consume(span);
}

Here JIT is expected to avoid calling Clear for new byte[len] path. Also, it should avoid it at all unless SkipLocalsInit is set.

Currently, in order to avoid this perf impact, developers complicate their code.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 20, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 20, 2024
@EgorBo EgorBo added this to the Future milestone Dec 20, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Dec 20, 2024
@Tornhoof
Copy link
Contributor

Honest question, how often is span.Clear() called in such patterns? I personally haven't done that ever at all I think.

@EgorBo
Copy link
Member Author

EgorBo commented Dec 20, 2024

Honest question, how often is span.Clear() called in such patterns? I personally haven't done that ever at all I think.

it's from BCL, in some cases we have to call Clear() because we know that SkipLocalsInit is defined globally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

2 participants