-
Notifications
You must be signed in to change notification settings - Fork 345
[SqlClient] Add benchmarks for SqlProcessor and implement initial quick wins #3031
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
base: main
Are you sure you want to change the base?
[SqlClient] Add benchmarks for SqlProcessor and implement initial quick wins #3031
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3031 +/- ##
==========================================
- Coverage 69.81% 69.71% -0.11%
==========================================
Files 403 413 +10
Lines 16184 16240 +56
==========================================
+ Hits 11299 11321 +22
- Misses 4885 4919 +34 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
test/OpenTelemetry.Contrib.Shared.Benchmarks/SqlProcessorBenchmarks.cs
Outdated
Show resolved
Hide resolved
- Avoid boxing using Dictionary rather than Hashtable - Set initial StringBuilder capacity - Avoid SubString on NET targets
11acc32
to
9af19eb
Compare
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.
Nice.
It's much easier to grok the improvement by looking at this 👍
Only some I know that you are adding benchmarks to the There are 2 options to fix it.
I have resolved conflicts with the main during review. EDIT: The second option is probably better from the infrastructure perspective, the first one, for the SqlClient developers. |
Contributes to #2238
Follow up from #3023
Changes
Implement some initial quick wins to avoid
SqlProcessor
overhead.Dictionary
rather thanHashtable
StringBuilder
capacitySubString
on NET targetsThese changes approximately half the time required when a statement is cached (moving to Dictionary). For non-cached statements they save approx 30% if the allocations and reduce execution time by approx 36%.
Before (with cache disabled)
After (with cache disabled)
I've left the summary benchmark results in SqlProcessorBenchmarks for comparison.We can save several hundred bytes per statement (exact saving depends on the input) by avoid the
StringBuilder
s. This is a larger change to switch to rented memory + span processing, at least for NET targets. I would expect execution time to reduce also. This is something I can investigate if we think the gain offsets the effort? I'd also look to remove theSqlProcessorState
to save another 40B per uncached statement.Merge requirement checklist
Unit tests added/updatedAppropriateCHANGELOG.md
files updated for non-trivial changesChanges in public API reviewed (if applicable)