Skip to content

[Jit] Improve struct passing (reduce copies) #25083

@benaadams

Description

@benaadams

Before they are out there and it becomes a breaking change (byval => byref)

ReadOnlyMemory is a readonly struct; currently a copy is made and that copy is then passed by reference; but there is an advantage to passing it in and no-disadvantage (as call-site doesn't need to be annotated with in) and since it is readonly and passed by ref anyway due to its size.

e.g. changing

static int CompareOrdinalIgnoreCase(ReadOnlySpan<char> strA, ReadOnlySpan<char> strB)

to

static int CompareOrdinalIgnoreCase(in ReadOnlySpan<char> strA, in ReadOnlySpan<char> strB)

Changes the call site from

G_M57521_IG05:
       lea      rcx, bword ptr [rsp+38H]
       mov      bword ptr [rcx], r9
       mov      dword ptr [rcx+8], edx
       lea      rcx, bword ptr [rsp+28H]
       mov      bword ptr [rcx], r8
       mov      dword ptr [rcx+8], edx
       lea      rcx, bword ptr [rsp+38H]
       lea      rdx, bword ptr [rsp+28H]
       call     CompareInfo:CompareOrdinalIgnoreCase(struct,struct):int

to

G_M57521_IG05:
       mov      bword ptr [rsp+28H], r8
       mov      dword ptr [rsp+30H], eax
       lea      rcx, bword ptr [rsp+28H]
       call     CompareInfo:CompareOrdinalIgnoreCase(byref,byref):int

/cc @jkotas @stephentoub @KrzysztofCwalina @mikedn

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions