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

Using the range operator will result in significant performance loss #66

Open
HMBSbige opened this issue Jan 11, 2024 · 0 comments
Open
Labels
Bug Something isn't working
Milestone

Comments

@HMBSbige
Copy link
Owner

Jit

using System;

public class X
{
    public void A(ref Span<byte> span, int i)
    {
        span = span[i..];
    }

    public void B(ref Span<byte> span, int i)
    {
        span = span.Slice(i);
    }
}
; Core CLR 8.0.23.53103 on x64

X..ctor()
    L0000: ret

X.A(System.Span`1<Byte> ByRef, Int32)
    L0000: sub rsp, 0x28
    L0004: mov rax, rdx
    L0007: mov eax, [rax+8]
    L000a: mov ecx, eax
    L000c: sub ecx, r8d
    L000f: mov r8d, r8d
    L0012: mov r10d, ecx
    L0015: add r10, r8
    L0018: cmp r10, rax
    L001b: ja short L002b
    L001d: add r8, [rdx]
    L0020: mov [rdx], r8
    L0023: mov [rdx+8], ecx
    L0026: add rsp, 0x28
    L002a: ret
    L002b: mov rax, 0x7ffb10a5ead8
    L0035: call qword ptr [rax]
    L0037: int3

X.B(System.Span`1<Byte> ByRef, Int32)
    L0000: sub rsp, 0x28
    L0004: mov eax, [rdx+8]
    L0007: cmp r8d, eax
    L000a: ja short L0020
    L000c: mov ecx, r8d
    L000f: add rcx, [rdx]
    L0012: sub eax, r8d
    L0015: mov [rdx], rcx
    L0018: mov [rdx+8], eax
    L001b: add rsp, 0x28
    L001f: ret
    L0020: mov rax, 0x7ffb10a5ead8
    L002a: call qword ptr [rax]
    L002c: int3

So just ignore IDE0057

@HMBSbige HMBSbige added the Bug Something isn't working label Jan 11, 2024
@HMBSbige HMBSbige added this to the Performance milestone Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant