Skip to content

reduce allocations in NpgsqlParameterCollection.AddRange - #6628

Open
mus65 wants to merge 1 commit into
npgsql:mainfrom
mus65:paramaddrange
Open

reduce allocations in NpgsqlParameterCollection.AddRange#6628
mus65 wants to merge 1 commit into
npgsql:mainfrom
mus65:paramaddrange

Conversation

@mus65

@mus65 mus65 commented Aug 8, 2026

Copy link
Copy Markdown

Call EnsureCapacity before inserting the items to avoid the list being resized multiple times. We noticed this in a GC trace with a query that has a lot of parameters for an IN() clause.

Benchmark before:

Method Mean Error StdDev Allocated
AddRange 41.69 us 0.335 us 0.297 us 40.3 KB

Benchmark after:

Method Mean Error StdDev Allocated
AddRange 40.19 us 0.441 us 0.345 us 15.82 KB

@mus65
mus65 requested review from roji and vonzshik as code owners August 8, 2026 10:21
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