From 3a0cc04c087708994d37b3a9e424f5201a125385 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Mon, 12 Apr 2021 11:00:23 -0700 Subject: [PATCH] rowenc: copy JSON bytes more efficiently in DecodeUntaggedDatum This commit changes a few lines of code in `rowenc.DecodeUntaggedDatum` that copy bytes from the `append([]byte{}, d...)` pattern to a combination of `make` and `copy`. The new pattern is slightly more efficient in Go 1.15.5, measured here: https://gist.github.com/mgartner/625af5169155da795df42854d0c8b8e5 Release note: None --- pkg/sql/rowenc/column_type_encoding.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/sql/rowenc/column_type_encoding.go b/pkg/sql/rowenc/column_type_encoding.go index da6b1c8b0117..45de3e3389de 100644 --- a/pkg/sql/rowenc/column_type_encoding.go +++ b/pkg/sql/rowenc/column_type_encoding.go @@ -647,8 +647,9 @@ func DecodeUntaggedDatum(a *DatumAlloc, t *types.T, buf []byte) (tree.Datum, []b // We copy the byte buffer here, because the JSON decoding is lazy, and we // do not want to hang on to the backing byte buffer, which might be an // entire KV batch. - data = append([]byte{}, data...) - j, err := json.FromEncoding(data) + cpy := make([]byte, len(data)) + copy(cpy, data) + j, err := json.FromEncoding(cpy) if err != nil { return nil, b, err }