Skip to content

Commit

Permalink
Allocate connRows on demand instead of preallocating in bulk
Browse files Browse the repository at this point in the history
The 64 element preallocatedRows may be pinning memory from previous
queries.

See #1127
  • Loading branch information
jackc committed Feb 19, 2022
1 parent 1e565b0 commit b6b24f9
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ type Conn struct {

connInfo *pgtype.ConnInfo

wbuf []byte
preallocatedRows []connRows
eqb extendedQueryBuilder
wbuf []byte
eqb extendedQueryBuilder
}

// Identifier a PostgreSQL identifier or name. Identifiers can be composed of
Expand Down Expand Up @@ -513,12 +512,7 @@ func (c *Conn) execPrepared(ctx context.Context, sd *pgconn.StatementDescription
}

func (c *Conn) getRows(ctx context.Context, sql string, args []interface{}) *connRows {
if len(c.preallocatedRows) == 0 {
c.preallocatedRows = make([]connRows, 64)
}

r := &c.preallocatedRows[len(c.preallocatedRows)-1]
c.preallocatedRows = c.preallocatedRows[0 : len(c.preallocatedRows)-1]
r := &connRows{}

r.ctx = ctx
r.logger = c
Expand Down

0 comments on commit b6b24f9

Please sign in to comment.