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

perf: Add invariant culture check result caching #376

Merged
merged 2 commits into from
Feb 6, 2020

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Jan 11, 2020

Every time SqlConnection.TryOpen is called the culture is checked to see if the runtime is in invariant mode and then throws because we can't run under culture invariant conditions. The culture object itself is cached so the check isn't too slow but in getting the cached object a string is allocated inside the runtime that can't be avoided. We can avoid most of this by caching the result of the first check because there is no way to change the invariant mode without restarting the runtime.

The enum is uint because it's the fastest comparison for the runtime. The assignment back to the static cached value isn't interlocked and it isn't really necessary to do so because if a small number of opens happen at the same time the last assigner will win and all assigners will get the same value so nothing is confused or lost it'll just exhibit the same performance as the current master would.

Copy link
Contributor

@David-Engel David-Engel left a comment

Choose a reason for hiding this comment

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

LGTM

@cheenamalhotra cheenamalhotra added the 📈 Performance Use this label for performance improvement activities label Feb 5, 2020
@cheenamalhotra cheenamalhotra added this to the 2.0.0-preview2 milestone Feb 5, 2020
@cheenamalhotra cheenamalhotra merged commit 031ad51 into dotnet:master Feb 6, 2020
@Wraith2 Wraith2 deleted the perf-cacheinvariantcheck branch February 7, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📈 Performance Use this label for performance improvement activities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants