sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Reduce allocations for PgBindIter

Open notABot101010 opened this issue 3 months ago • 1 comments

I have found these related issues/pull requests

#3651

Description

Hello, The new PgBindIter is awesome, but it seems that it allocates too much memory.

I would like to submit a PR to .reserve() the PgArgumentBuffer using iter.size_hint() in encode_inner https://github.com/launchbadge/sqlx/blob/e8384f2a00173c2b120eea72e99d120557fced8b/sqlx-postgres/src/bind_iter.rs#L83

in order to reduce the number of allocations performed by PgArgumentBuffer.

Prefered solution

.reserve() the PgArgumentBuffer using iter.size_hint() in encode_inner

Is this a breaking change? Why or why not?

no, just a small improvement, 1-line change

notABot101010 avatar Nov 03 '25 16:11 notABot101010

We should probably also override the default Encode::size_hint impl to also use Iterator::size_hint.

Although we don't do this for Vec?

joeydewaal avatar Nov 06 '25 20:11 joeydewaal