Is your feature request related to a problem? Please describe.
I recently migrated parts of my codebase to pgx v5 and have started using the amazing pgx.CollectRows utility to easily serialise my structures. Some of my old business logic used to load up paginated queries into struct slices.
I usually followed very strict rules of allocating enough slice capacity at initialisation to avoid go's slice append from 'growing' my slice every now and then. In other words, paginated queries initialise a slice with capacity equal to the pagination limit, effectively avoiding slice resizing happening for worst-case scenarios.
Debates aside on whether this is a good practice or not, I found myself not having this option anymore since pgx.CollectRows will handle the slice initialisation and fill via append.
I would like to bring into discussion this topic and see what are everyone's thoughts.
Describe the solution you'd like
pgx CollectRows to intelligently allocate enough slice capacity to reduce the number of allocations due slice resizing particularly happening in paginated queries, which are somewhat predictable in upper bound capacity limit
Is your feature request related to a problem? Please describe.
I recently migrated parts of my codebase to pgx
v5
and have started using the amazingpgx.CollectRows
utility to easily serialise my structures. Some of my old business logic used to load up paginated queries into struct slices.I usually followed very strict rules of allocating enough slice capacity at initialisation to avoid go's slice
append
from 'growing' my slice every now and then. In other words, paginated queries initialise a slice with capacity equal to the pagination limit, effectively avoiding slice resizing happening for worst-case scenarios.Debates aside on whether this is a good practice or not, I found myself not having this option anymore since
pgx.CollectRows
will handle the slice initialisation and fill viaappend
.I would like to bring into discussion this topic and see what are everyone's thoughts.
Describe the solution you'd like
pgx
CollectRows
to intelligently allocate enough slice capacity to reduce the number of allocations due slice resizing particularly happening in paginated queries, which are somewhat predictable in upper bound capacity limitDescribe alternatives you've considered
Alternatives are to not make use of
CollectRows
Additional context