Avoid some defensive copies on readonly structs in System.Net.Quic#101133
Avoid some defensive copies on readonly structs in System.Net.Quic#101133rzikm merged 9 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @dotnet/ncl |
|
cc: @hamarb123 |
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
|
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Net.Quic/src/System/Net/Quic/Interop/msquic.cs
Outdated
Show resolved
Hide resolved
| internal unsafe partial struct QUIC_BUFFER | ||
| { | ||
| public Span<byte> Span => new(Buffer, (int)Length); | ||
| public readonly Span<byte> Span => new(Buffer, (int)Length); |
There was a problem hiding this comment.
I don't remember exactly, but if this is generated code from MsQuic, it should be fixed there as well.
There was a problem hiding this comment.
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.
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
…uicConfiguration.Cache.cs Co-authored-by: Marie Píchová <11718369+ManickaP@users.noreply.github.com>
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
Show resolved
Hide resolved
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/ReceiveBuffers.cs
Outdated
Show resolved
Hide resolved
|
|
||
| namespace Microsoft.Quic | ||
| { | ||
| internal partial struct QUIC_SETTINGS : System.IEquatable<QUIC_SETTINGS> |
There was a problem hiding this comment.
Why is this needed? Is QUIC_SETTINGS being put into a Dictionary somewhere or something?
There was a problem hiding this comment.
QUIC_SETTINGS is used as part of the cache key for MsQuicConfigurationHandle
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
| /// 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; |
There was a problem hiding this comment.
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.
src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.Cache.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Quic/src/System/Net/Quic/Interop/QUIC_SETTINGS.IEquattable.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Quic/src/System/Net/Quic/Interop/QUIC_SETTINGS.IEquattable.cs
Outdated
Show resolved
Hide resolved
|
CI failures are unrelated. |
…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>
…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>
…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>
This removes defensive copies on readonly structs in S.N.S uncovered by an analyzer from a community member (thanks @hamarb123!).