-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Optimize performance of SecurityIdentifier.ToString() #33579
Conversation
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
The packaging build failure indicates that Span<> isn't found for the netcoreapp2.0 build I think. Any suggestions? |
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
Keep the existing code under ifdef for netstandard and netcoreapp2.0 configurations. Alternatively, we may stop building netstandard and netcoreapp2.0 version of the package. @safern Is it an option for this package? |
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Outdated
Show resolved
Hide resolved
adress feedback
src/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than my request about tests, this LGTM. Thanks for doing this.
It would be an option, yes. However it has its pros and cons: Pros:
Cons:
We should also consider the following options for this package:
So everything comes to the following question: Do we consider this package API complete to freeze its API? I think for the 3.0 effort we're having some APIs being added to this package (maybe still on PR) so we should make sure this package is API complete before making that call. From looking at this changes, I would also suggest if we don't want to freeze the API and/or make its ref inbox, currently the way it is. The PR would need the following changes:
cc: @ericstj |
src/System.Security.Principal.Windows/tests/SecurityIdentifierTests.cs
Outdated
Show resolved
Hide resolved
src/System.Security.Principal.Windows/tests/SecurityIdentifierTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a netcoreapp2.1 configuration into configurations.props in the src project. Per: #33579 (comment)
This should be under the PackageConfigurations. So it would look like:
<PackageConfigurations>
netstandard;
netcoreapp2.0-Windows_NT;
netcoreapp2.0-Unix;
netcoreapp2.1-Windows_NT;
netcoreapp2.1-Unix;
net461-Windows_NT;
</PackageConfigurations>
<BuildConfigurations>
$(PackageConfigurations)
netcoreapp-Windows_NT;
netcoreapp-Unix;
uap-Windows_NT;
netfx-Windows_NT;
</BuildConfigurations>
You will also need to update the property in the source project. You can also achieve this by running dotnet msbuild /t:UpdateVSConfigurations
in the root of the repo. (This might update other projects though)
Also, no need to ifdef for netstandard: #if netcoreapp20
should be enough, we're not including this sources into the netstandard build.
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update the property to include netcoreapp2.1? https://github.com/dotnet/corefx/blob/master/src/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj#L9
Do you mean add 2.1 variants of all the 2.0 entries in that list? |
You can just run |
ok, all done. |
Looks like it's coming from netcoreapp2.1-Windows_NT. That pinvoke is still in the |
Any ideas on the interop error? |
You just need to duplicate this file: https://github.com/dotnet/corefx/blob/master/src/System.Security.Principal.Windows/src/PinvokeAnalyzerExceptionList.analyzerdata.netcoreapp and rename it to |
Osx build failure is unrelated, i'll request a retest but otherwise it looks done. |
in SqlClient when using trusted authentication the windows user identity is used as part of the pool key. Profiling has shown that getting the user sid is on the hot path for this and that optimizing the retrieval of the SecurityIdentifier string form will improve connection throughput.
This change avoids the use of a StringBuilder, it's expansion and formatting intermediate strings by using a stackalloc span of the maximum possible length for a v1 string form sid and formatting directly into that buffer. The size calculation is included in the comments so the next person to look at this code doesn't have to work it out for themselves.
The stackalloc buffer is 189 chars in length which looks odd but remember that chars are 16bit so this buffer is still 16bit aligned on the stack. It could be increased up to the closest power of 2 (192) if this is desirable, I know there are rules about this which @GrabYourPitchforks will need to review.
Performance changes make it almost 50% faster and change the memory allocation from using StringBuilder expansion and intermediate formatting representation strings to a flat allocation at the end of the method to return the string.
/CC @GrabYourPitchforks , @bartonjs
Contributes to https://github.com/dotnet/corefx/issues/30430 @saurabh500