]> Cypherpunks repositories - gostls13.git/commit
encoding/csv: Preallocate records slice
authorJustin Nuß <nuss.justin@gmail.com>
Mon, 13 Apr 2015 18:13:14 +0000 (20:13 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 26 Apr 2015 16:28:51 +0000 (16:28 +0000)
commit2db58f8f2daea1c6f6134584f7811bb229177b28
treec51049b2c0e3d213d961e8e7c9724bdc32df9012
parenta5b693b431d0612b97a8978fdfa7d12310d95b6f
encoding/csv: Preallocate records slice

Currently parseRecord will always start with a nil
slice and then resize the slice on append. For input
with a fixed number of fields per record we can preallocate
the slice to avoid having to resize the slice.

This change implements this optimization by using
FieldsPerRecord as capacity if it's > 0 and also adds a
benchmark to better show the differences.

benchmark         old ns/op     new ns/op     delta
BenchmarkRead     19741         17909         -9.28%

benchmark         old allocs     new allocs     delta
BenchmarkRead     59             41             -30.51%

benchmark         old bytes     new bytes     delta
BenchmarkRead     6276          5844          -6.88%

Change-Id: I7c2abc9c80a23571369bcfcc99a8ffc474eae7ab
Reviewed-on: https://go-review.googlesource.com/8880
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/encoding/csv/reader.go
src/encoding/csv/reader_test.go