Skip to content

Commit

Permalink
sql/pgwire: avoid new memory allocation in writeTextDatum(Date)
Browse files Browse the repository at this point in the history
3dfd6cb introduced a performance regression in the speed of encoding
Date datums to their text representation. This commit partially avoids
the regression.

```
name              old time/op  new time/op  delta
WriteTextDate-16   446ns ± 4%   318ns ± 1%  -28.75%  (p=0.000 n=10+9)
```

Release justification: Avoids performance regression.

Release note: None
  • Loading branch information
nvanbenschoten committed Oct 8, 2019
1 parent 27ea46b commit becd567
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/sql/pgwire/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ func (b *writeBuffer) writeTextDatum(
b.writeLengthPrefixedString(v.Contents)

case *tree.DDate:
s := v.Date.String()
b.putInt32(int32(len(s)))
b.write([]byte(s))
b.textFormatter.FormatNode(v)
b.writeFromFmtCtx(b.textFormatter)

case *tree.DTime:
// Start at offset 4 because `putInt32` clobbers the first 4 bytes.
Expand Down

0 comments on commit becd567

Please sign in to comment.