Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[No Merge][WIP] SequenceReader pass ReadOnlySequence via in#35678

Closed
benaadams wants to merge 1 commit intodotnet:masterfrom
benaadams:seqreader
Closed

[No Merge][WIP] SequenceReader pass ReadOnlySequence via in#35678
benaadams wants to merge 1 commit intodotnet:masterfrom
benaadams:seqreader

Conversation

@benaadams
Copy link
Copy Markdown
Member

@benaadams benaadams commented Mar 1, 2019

Its a 32-byte 4 element readonly struct so it avoids a chunky copy in the call site

/cc @JeremyKuhne @ahsonkhan @pakrym

public ref partial struct SequenceReader<T> where T : unmanaged, System.IEquatable<T>
{
public SequenceReader(System.Buffers.ReadOnlySequence<T> sequence) { throw null; }
public SequenceReader(in System.Buffers.ReadOnlySequence<T> sequence) { throw null; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't all of these breaking changes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And if they're not because we haven't shipped any of these yet, it's still a public API change that needs to go through a public API review process.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to change SequenceReader as its only 3.0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to change SequenceReader as its only 3.0?

If you want to change it, please open an issue for it as it needs to go through API review.

I would, however, urge us to avoid polluting methods like this with in unless we find that a) it makes a meaningful difference and b) we expect that difference will never be able to captured by JIT-level changes instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drops 32-bytes of stack zeroing and this from call site

vmovdqu  xmm0, qword ptr [rbx]
vmovdqu  qword ptr [rbp-1D0H], xmm0
vmovdqu  xmm0, qword ptr [rbx+16]
vmovdqu  qword ptr [rbp-1C0H], xmm0

Its a 4 element struct so its unlikely to be covered by calling convention; however it is also an Aggressive Inline (albeit a frighteningly large one) and there has been speculation that the Jit could eventually elide the copy (@mikedn mentioned it on the ValueTaskAwaiter PR); though it doesn't currently.

Will open api issue for discussion.

Copy link
Copy Markdown
Member

@stephentoub stephentoub Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

albeit a frighteningly large one

Yeah, I'm not sure why it's annotated that way. Seems like a "this helped a microbenchmark" kind of usage that could actually have an overall negative impact, but I've not looked in detail.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume as its an even more chunky struct; so if it didn't inline the constructor would be immediately be followed by 2x 104 byte copies

Type layout for 'SequenceReader`1'
Size: 104 bytes. Paddings: 23 bytes (%22 of empty space)

Once for copying from the return stack to method stack; followed by method stack to method stack for the assignment to local (as seen in dotnet/coreclr#22738)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. this innocuous line

var start = default(SequenceReader<byte>);

is

G_M20026_IG23:
       33C9                 xor      rcx, rcx
       488D85F8FEFFFF       lea      rax, bword ptr [rbp-108H]
       C5F857C0             vxorps   xmm0, xmm0
       C5FA7F00             vmovdqu  qword ptr [rax], xmm0
       C5FA7F4010           vmovdqu  qword ptr [rax+16], xmm0
       C5FA7F4020           vmovdqu  qword ptr [rax+32], xmm0
       C5FA7F4030           vmovdqu  qword ptr [rax+48], xmm0
       C5FA7F4040           vmovdqu  qword ptr [rax+64], xmm0
       C5FA7F4050           vmovdqu  qword ptr [rax+80], xmm0
       48894860             mov      qword ptr [rax+96], rcx
       898DF4FEFFFF         mov      dword ptr [rbp-10CH], ecx

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though made PR to resolve that dotnet/aspnetcore#8076

Comment thread src/System.Memory/ref/System.Memory.cs Outdated
@benaadams benaadams changed the title System.Memory pass ReadOnlySequence via in SequenceReader pass ReadOnlySequence via in Mar 1, 2019
@benaadams benaadams changed the title SequenceReader pass ReadOnlySequence via in [No Merge][WIP] SequenceReader pass ReadOnlySequence via in Mar 1, 2019
@karelz
Copy link
Copy Markdown
Member

karelz commented Mar 18, 2019

@benaadams do you have rough timeline in mind for this PR?

@benaadams
Copy link
Copy Markdown
Member Author

@karelz
Copy link
Copy Markdown
Member

karelz commented Mar 18, 2019

@benaadams ah ... wanna stop by at API review tomorrow and help push it through? ;)
cc @terrajobst

@karelz karelz added blocked Issue/PR is blocked on something - see comments * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) labels Mar 18, 2019
@stephentoub
Copy link
Copy Markdown
Member

Closing per API review.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Memory blocked Issue/PR is blocked on something - see comments * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants