Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Merge | SniNativeWrapper Interface#3015

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
benrr101 merged 13 commits intodotnet:mainfrombenrr101:merge/sniwrapper-interface
Nov 27, 2024

Conversation

benrr101
Copy link
Contributor

@benrr101benrr101 commentedNov 18, 2024
edited
Loading

Description: This is part 2 of 2 for merging SNI native method wrappers. It's a little more involved than before and requires a bit of explanation.

In the netfx version of the SNI native wrapper, the SniNativeWrapper class is truly a wrapper around three native libraries (x86, x64, and arm64). The prior code for this had a switch on each case that would check the architecture of the system and call the appropriate native library. This isn't ideal since it requires a switch statement each time a native SNI call is made. A better approach would be to have the wrapper call into a native library that is picked at static construction of the wrapper.

However, there are limitations to this approach:

  1. The only difference between the three native libraries is the name of the[DllImport] dll. However, this must be a compile time constant. This means there must be a class for each of the native libraries.
  2. In order to use[DllImport], the method must beextern, which must bestatic. Interfaces cannot have static methods (at least not prior to net7, iirc), so in order for the library classes to implement an interface, they have to have an instance method that calls into the static, extern method.
  3. The easiest way to integrate the netcore implementation into this pattern is to have a implementation of the interface that uses the netcore dll. This introduces a bit of unnecessary indirection, but I think it will be negligible.

Thus, here is the class hierarchy:

  • SNINativeMethodWrapper [netfx],SNINativeMethodWrapper.Windows [netcore]
    • ISniNativeWrapper [netfx, netcore]
      • SniNativeMethods [netcore]
      • SniNativeMethodsArm64 [netfx]
      • SniNativeMethodsNotSupported [netfx] - used when architecture is not supported
      • SniNativeMethodsX64 [netfx]
      • SniNativeMethodsX86 [netfx]

Although I can't speak in specifics, when comparing the performance of a switch per call and calling an interface which calls the method, the interface approach is significantly more performant. (sorry@David-Engel )

Testing: For the most part, this just moves code around and doesn't really change the functionality. Everythingshould still work, but the native SNI CI tests will confirm.

David-Engel reacted with laugh emojiDavid-Engel reacted with heart emoji
@benrr101benrr101 added the Common Project 🚮Things that relate to the common project project labelNov 18, 2024
@codecovCodecov
Copy link

codecovbot commentedNov 18, 2024
edited
Loading

Codecov Report

Attention: Patch coverage is95.09804% with15 lines in your changes missing coverage. Please review.

Project coverage is 72.72%. Comparing base(b9877f4) to head(696c949).
Report is 3 commits behind head on main.

Files with missing linesPatch %Lines
...src/Microsoft/Data/SqlClient/LocalDBAPI.Windows.cs0.00%4 Missing⚠️
...Client/src/Interop/Windows/Sni/SniNativeWrapper.cs98.05%4 Missing⚠️
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs75.00%3 Missing⚠️
...t/netfx/src/Microsoft/Data/SqlClient/LocalDBAPI.cs0.00%2 Missing⚠️
...osoft/Data/SqlClient/TdsParserStateObjectNative.cs95.00%1 Missing⚠️
...ft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs85.71%1 Missing⚠️
Additional details and impacted files
@@             Coverage Diff             @@##             main    #3015       +/-   ##===========================================- Coverage   92.58%   72.72%   -19.86%===========================================  Files           6      283      +277       Lines         310    58975    +58665     ===========================================+ Hits          287    42892    +42605- Misses         23    16083    +16060
FlagCoverage Δ
addons92.58% <ø> (ø)
netcore75.49% <94.30%> (?)
netfx71.19% <94.71%> (?)

Flags with carried forward coverage won't be shown.Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

Copy link
Contributor

@edwardnealedwardneal left a comment

Choose a reason for hiding this comment

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

I was actually wondering how we were going to approach this merge. I've only got a few comments on the way the PR handles the approach, but are there any wider plans to merge the references to the two native SNI packages?


Although I can't speak in specifics, when comparing the performance of a switch per call and calling an interface which calls the method, the interface approach is significantly more performant.

That's true in this case, but the JIT will also make its presence felt.RuntimeInformation.ProcessArchitecture is a constant expression at runtime, so the JIT will see a switch with a constant expression and optimise it away. On .NET Core, you might not actually have a switch expression at all.

@benrr101benrr101force-pushed themerge/sniwrapper-interface branch from469f92a to4eb92bfCompareNovember 19, 2024 23:51
Copy link
Contributor

@mdaiglemdaigle left a comment

Choose a reason for hiding this comment

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

LGTM

@benrr101benrr101force-pushed themerge/sniwrapper-interface branch from4eb92bf to696c949CompareNovember 26, 2024 20:52
@benrr101benrr101 merged commit46e8714 intodotnet:mainNov 27, 2024
252 checks passed
@benrr101benrr101 deleted the merge/sniwrapper-interface branchNovember 27, 2024 18:33
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@edwardnealedwardnealedwardneal left review comments

@mdaiglemdaiglemdaigle approved these changes

@David-EngelDavid-EngelDavid-Engel approved these changes

@saurabh500saurabh500Awaiting requested review from saurabh500

@cheenamalhotracheenamalhotraAwaiting requested review from cheenamalhotra

@samsharma2700samsharma2700Awaiting requested review from samsharma2700

Assignees
No one assigned
Labels
Common Project 🚮Things that relate to the common project project
Projects
None yet
Milestone
6.1-preview1
Development

Successfully merging this pull request may close these issues.

5 participants
@benrr101@mdaigle@David-Engel@edwardneal@cheenamalhotra

[8]ページ先頭

©2009-2025 Movatter.jp