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

Avoid some defensive copies on readonly structs in System.Net.Quic #101133

Merged
merged 9 commits into from
Apr 25, 2024

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Apr 16, 2024

This removes defensive copies on readonly structs in S.N.S uncovered by an analyzer from a community member (thanks @hamarb123!).

Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@rzikm rzikm requested a review from a team April 16, 2024 18:28
@MihaZupan
Copy link
Member

cc: @hamarb123

Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

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

Thanks

@rzikm
Copy link
Member Author

rzikm commented Apr 16, 2024

/azp run runtime

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -20,7 +20,7 @@ namespace Microsoft.Quic
{
internal unsafe partial struct QUIC_BUFFER
{
public Span<byte> Span => new(Buffer, (int)Length);
public readonly Span<byte> Span => new(Buffer, (int)Length);
Copy link
Member

Choose a reason for hiding this comment

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

I don't remember exactly, but if this is generated code from MsQuic, it should be fixed there as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

right, I thought this was added manually by us (since the QUIC_BUFFER definition is in another auto-generated file). I will follow up to make the change in their repo as well.

rzikm and others added 2 commits April 17, 2024 11:33
…uicConfiguration.Cache.cs

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
@rzikm
Copy link
Member Author

rzikm commented Apr 22, 2024

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


namespace Microsoft.Quic
{
internal partial struct QUIC_SETTINGS : System.IEquatable<QUIC_SETTINGS>
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Is QUIC_SETTINGS being put into a Dictionary somewhere or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

QUIC_SETTINGS is used as part of the cache key for MsQuicConfigurationHandle

@@ -88,7 +88,7 @@ internal sealed class MsQuicContextSafeHandle : MsQuicSafeHandle
/// Holds a weak reference to the managed instance.
/// It allows delegating MsQuic events to the managed object while it still can be collected and finalized.
/// </summary>
private readonly GCHandle _context;
private GCHandle _context;
Copy link
Member

Choose a reason for hiding this comment

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

Unintended leftover change?

Copy link
Member Author

Choose a reason for hiding this comment

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

This one should stay, otherwise the .Free() is executed on a defensive copy

It probably is not a big deal since ReleaseHandle runs exactly once, but we still make sure to cleanup dangling pointers.

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

Nits, otherwise LGTM.

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

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

LGTM

@rzikm
Copy link
Member Author

rzikm commented Apr 25, 2024

CI failures are unrelated.

@rzikm rzikm merged commit aa07770 into dotnet:main Apr 25, 2024
78 of 84 checks passed
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…otnet#101133)

* Avoid some defensive copies on readonly structs in System.Net.Quic

* Keep readonly-ness of CacheKey

* Apply suggestions from code review

* Remove ReadOnlySpan property

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>

* Code review feedback

* Implement IEquattable for QUIC_SETTINGS

* More code review feedback

* Code review feedback

---------

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…otnet#101133)

* Avoid some defensive copies on readonly structs in System.Net.Quic

* Keep readonly-ness of CacheKey

* Apply suggestions from code review

* Remove ReadOnlySpan property

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>

* Code review feedback

* Implement IEquattable for QUIC_SETTINGS

* More code review feedback

* Code review feedback

---------

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
@karelz karelz added this to the 9.0.0 milestone May 14, 2024
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
…otnet#101133)

* Avoid some defensive copies on readonly structs in System.Net.Quic

* Keep readonly-ness of CacheKey

* Apply suggestions from code review

* Remove ReadOnlySpan property

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>

* Code review feedback

* Implement IEquattable for QUIC_SETTINGS

* More code review feedback

* Code review feedback

---------

Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants