Skip to content

Reduce allocations when binding scalar parameters#344

Open
skuirrels wants to merge 1 commit into
Giorgi:developfrom
skuirrels:feature/direct-native-scalar-bind-pr
Open

Reduce allocations when binding scalar parameters#344
skuirrels wants to merge 1 commit into
Giorgi:developfrom
skuirrels:feature/direct-native-scalar-bind-pr

Conversation

@skuirrels

Copy link
Copy Markdown
Contributor

Problem

Scalar parameters currently create a temporary duckdb_value, bind it, and dispose it on every execution. That adds wrapper overhead for common values such as numbers, strings, dates, and blobs.

Solution

Use DuckDB's type-specific native bind functions for scalar values. Collections and types that need an exact logical representation keep the existing duckdb_value fallback. byte[] continues to bind as a collection for LIST/ARRAY targets and as BLOB otherwise.

Benchmark

.NET 10 Release, 5 warmups, 10 measured iterations, three scalar parameters:

Metric Before After Change
Prepared execution 23.50 us 22.23 us -5.4%
Prepared allocation 1,064 B 944 B -11.3%
Unprepared execution 62.96 us 60.59 us -3.8%
Unprepared allocation 1,296 B 1,176 B -9.3%

The stable result is 120 fewer managed bytes per execution; timing is naturally noisier.

Tests

  • 6,898 tests passed on the isolated develop-based branch
  • Added byte[] LIST and fixed ARRAY regression coverage
  • Existing BLOB coverage passes

@skuirrels
skuirrels marked this pull request as ready for review July 21, 2026 09:22
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.21168% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.67%. Comparing base (fe2abc5) to head (0aeb7b3).

Files with missing lines Patch % Lines
...NET.Data/PreparedStatement/ClrToDuckDBConverter.cs 82.83% 4 Missing and 19 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #344      +/-   ##
===========================================
- Coverage    87.59%   86.67%   -0.92%     
===========================================
  Files           77       77              
  Lines         3143     3264     +121     
  Branches       466      482      +16     
===========================================
+ Hits          2753     2829      +76     
- Misses         276      310      +34     
- Partials       114      125      +11     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant