This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Optimize SqlClient tds state to remove handle boxing #34044
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ba78a61
change TdsParserStateObject to pass packets using a ref struct to avo…
Wraith2 1a8f447
add project define for FEATURE_INTEROPSNI on windows non uap builds
Wraith2 7ac5553
update interop to use SniPacketHandle type name
Wraith2 1d6235d
rename SNIPacketHandle to SNIPacket
Wraith2 f98c9e5
fix merge conflicts
Wraith2 76b688e
fix merge conflict
Wraith2 1e1f540
split PacketHandle and SessionHandle into separate files and implemen…
Wraith2 69a8337
add comments to PacketHandle and SessionHandle
Wraith2 6b1900c
move lazy bool into debug region
Wraith2 dc24084
re-add EmptyReadPackt and provide correctly types valid but empty pac…
Wraith2 4801eb3
change implementation switch name to make more sense
Wraith2 a76208f
add packet type assertion in IsValiePacket
Wraith2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/System.Data.SqlClient/src/System/Data/SqlClient/PacketHandle.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
|
|
||
| namespace System.Data.SqlClient | ||
| { | ||
| // this structure is used for transporting packet handle references between the TdsParserStateObject | ||
| // base class and Managed or Native implementations. | ||
| // It prevents the native IntPtr type from being boxed and prevents the need to cast from object which loses compile time type safety | ||
| // It carries type information so that assertions about the type of handle can be made in the implemented abstract methods | ||
| // it is a ref struct so that it can only be used to transport the handles and not store them | ||
|
|
||
| // N.B. If you change this type you must also change the version for the other platform | ||
|
|
||
| internal readonly ref struct PacketHandle | ||
| { | ||
| public const int NativePointerType = 1; | ||
| public const int NativePacketType = 2; | ||
| public const int ManagedPacketType = 3; | ||
|
|
||
| public readonly SNI.SNIPacket ManagedPacket; | ||
| public readonly int Type; | ||
|
|
||
| private PacketHandle(SNI.SNIPacket managedPacket, int type) | ||
| { | ||
| Type = type; | ||
| ManagedPacket = managedPacket; | ||
| } | ||
|
|
||
| public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => new PacketHandle(managedPacket, ManagedPacketType); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/System.Data.SqlClient/src/System/Data/SqlClient/PacketHandle.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
|
|
||
| namespace System.Data.SqlClient | ||
| { | ||
| // this structure is used for transporting packet handle references between the TdsParserStateObject | ||
| // base class and Managed or Native implementations. | ||
| // It prevents the native IntPtr type from being boxed and prevents the need to cast from object which loses compile time type safety | ||
| // It carries type information so that assertions about the type of handle can be made in the implemented abstract methods | ||
| // it is a ref struct so that it can only be used to transport the handles and not store them | ||
|
|
||
| // N.B. If you change this type you must also change the version for the other platform | ||
|
|
||
| internal readonly ref struct PacketHandle | ||
| { | ||
| public const int NativePointerType = 1; | ||
| public const int NativePacketType = 2; | ||
| public const int ManagedPacketType = 3; | ||
|
|
||
| public readonly IntPtr NativePointer; | ||
| public readonly SNIPacket NativePacket; | ||
|
|
||
| public readonly SNI.SNIPacket ManagedPacket; | ||
| public readonly int Type; | ||
|
|
||
| private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, SNI.SNIPacket managedPacket, int type) | ||
| { | ||
| Type = type; | ||
| ManagedPacket = managedPacket; | ||
| NativePointer = nativePointer; | ||
| NativePacket = nativePacket; | ||
| } | ||
|
|
||
| public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => new PacketHandle(default, default, managedPacket, ManagedPacketType); | ||
|
|
||
| public static PacketHandle FromNativePointer(IntPtr nativePointer) => new PacketHandle(nativePointer, default, default, NativePointerType); | ||
|
|
||
| public static PacketHandle FromNativePacket(SNIPacket nativePacket) => new PacketHandle(default, nativePacket, default, NativePacketType); | ||
|
|
||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/System.Data.SqlClient/src/System/Data/SqlClient/SessionHandle.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
|
|
||
| namespace System.Data.SqlClient | ||
| { | ||
| // this structure is used for transporting packet handle references between the TdsParserStateObject | ||
| // base class and Managed or Native implementations. | ||
| // It carries type information so that assertions about the type of handle can be made in the | ||
| // implemented abstract methods | ||
| // it is a ref struct so that it can only be used to transport the handles and not store them | ||
|
|
||
| // N.B. If you change this type you must also change the version for the other platform | ||
|
|
||
| internal readonly ref struct SessionHandle | ||
| { | ||
| public const int NativeHandleType = 1; | ||
| public const int ManagedHandleType = 2; | ||
|
|
||
| public readonly SNI.SNIHandle ManagedHandle; | ||
| public readonly int Type; | ||
|
|
||
| public SessionHandle(SNI.SNIHandle managedHandle, int type) | ||
| { | ||
| Type = type; | ||
| ManagedHandle = managedHandle; | ||
| } | ||
|
|
||
| public bool IsNull => ManagedHandle is null; | ||
|
|
||
| public static SessionHandle FromManagedSession(SNI.SNIHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, ManagedHandleType); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/System.Data.SqlClient/src/System/Data/SqlClient/SessionHandle.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
|
|
||
| namespace System.Data.SqlClient | ||
| { | ||
| // this structure is used for transporting packet handle references between the TdsParserStateObject | ||
| // base class and Managed or Native implementations. | ||
| // It carries type information so that assertions about the type of handle can be made in the | ||
| // implemented abstract methods | ||
| // it is a ref struct so that it can only be used to transport the handles and not store them | ||
|
|
||
| // N.B. If you change this type you must also change the version for the other platform | ||
|
|
||
| internal readonly ref struct SessionHandle | ||
Wraith2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public const int NativeHandleType = 1; | ||
| public const int ManagedHandleType = 2; | ||
|
|
||
| public readonly SNI.SNIHandle ManagedHandle; | ||
| public readonly SNIHandle NativeHandle; | ||
|
|
||
| public readonly int Type; | ||
|
|
||
| public SessionHandle(SNI.SNIHandle managedHandle, SNIHandle nativeHandle, int type) | ||
| { | ||
| Type = type; | ||
| ManagedHandle = managedHandle; | ||
| NativeHandle = nativeHandle; | ||
| } | ||
|
|
||
| public bool IsNull => (Type == NativeHandleType) ? NativeHandle is null : ManagedHandle is null; | ||
|
|
||
| public static SessionHandle FromManagedSession(SNI.SNIHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, default, ManagedHandleType); | ||
|
|
||
| public static SessionHandle FromNativeHandle(SNIHandle nativeSessionHandle) => new SessionHandle(default, nativeSessionHandle, NativeHandleType); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.