sqlx
sqlx copied to clipboard
Reduce allocations for PgBindIter
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
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?