Skip to content

Avoid iterator allocation for prepared ExecuteNonQuery#1

Draft
skuirrels wants to merge 1 commit into
feature/prepared-command-reusefrom
feature/single-result-prepared-execution
Draft

Avoid iterator allocation for prepared ExecuteNonQuery#1
skuirrels wants to merge 1 commit into
feature/prepared-command-reusefrom
feature/single-result-prepared-execution

Conversation

@skuirrels

Copy link
Copy Markdown
Owner

Stacked on Giorgi#340 so the diff stays focused on this follow-up.

Problem

Prepared ExecuteNonQuery() still goes through an IEnumerable iterator even though a reusable prepared command contains one statement. That adds a fixed 112-byte allocation to every execution.

Solution

Execute that single prepared result directly, while keeping the existing iterator path for readers, unprepared commands, and multi-statement commands. Prepared-statement lifecycle and deferred disposal still use the same shared bookkeeping.

Benchmark

Median of 7 runs after warmup, 20,000 executions per run:

Workload Before After Change
No parameters 112 B/op 0 B/op -100%
Three parameters 232 B/op 120 B/op -48.3%

The remaining 120 bytes come from parameter-value wrappers and are outside this change. Timing varied within noise; the allocation reduction was stable.

Tests

  • DuckDBCommandTests: 13 passed
  • Full suite: 6,907 passed, 0 failed

skuirrels commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

This is stacked on Giorgi#340 and should only be merged after Giorgi#340 has been merged. I have therefore left in draft state.

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