Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85)

Issue 108240044: code review 108240044: archive/tar: reuse temporary buffer in readHeader (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 11 months ago by unclejack
Modified:
9 years, 10 months ago
Reviewers:
dsymonds
CC:
golang-codereviews, dave_cheney.net, dsymonds, bradfitz
Visibility:
Public.

Description

archive/tar: reuse temporary buffer in readHeader A temporary 512 bytes buffer is allocated for every call to readHeader. This buffer isn't returned to the caller and it could be reused to lower the number of memory allocations. This CL improves it by using a pool and zeroing out the buffer before putting it back into the pool. benchmark old ns/op new ns/op delta BenchmarkListFiles100k 545249903 538832687 -1.18% benchmark old allocs new allocs delta BenchmarkListFiles100k 2105167 2005692 -4.73% benchmark old bytes new bytes delta BenchmarkListFiles100k 105903472 54831527 -48.22% This improvement is very important if your code has to deal with a lot of tarballs which contain a lot of files.

Patch Set 1 #

Patch Set 2 : diff -r 363e78454ccd https://code.google.com/p/go/ #

Patch Set 3 : diff -r 363e78454ccd https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+8 lines, -5 lines) Patch
M src/pkg/archive/tar/reader.go View 1 2 2 chunks +8 lines, -5 lines 0 comments Download

Messages

Total messages: 15
unclejack
Hello golang-codereviews@googlegroups.com (cc: bradfitz@golang.org, golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
9 years, 11 months ago (2014-06-27 20:24:14 UTC) #1
bradfitz
This is a bad use of sync.Pool. Just put a []byte that you re-use off ...
9 years, 11 months ago (2014-06-27 20:43:34 UTC) #2
unclejack
Hello, I've updated it based on your feedback. PTAL benchmark old ns/op new ns/op delta ...
9 years, 11 months ago (2014-06-27 21:43:38 UTC) #3
dave_cheney.net
You may be able to improve this further using the 'slice of byte array' trick. ...
9 years, 11 months ago (2014-06-29 00:04:07 UTC) #4
unclejack
I've updated the patch. On 2014/06/29 00:04:07, dfc wrote: > You may be able to ...
9 years, 10 months ago (2014-06-29 15:56:17 UTC) #5
bradfitz
R=dsymonds
9 years, 10 months ago (2014-07-01 17:54:47 UTC) #6
dsymonds
LGTM one little change please https://codereview.appspot.com/108240044/diff/60001/src/pkg/archive/tar/reader.go File src/pkg/archive/tar/reader.go (right): https://codereview.appspot.com/108240044/diff/60001/src/pkg/archive/tar/reader.go#newcode431 src/pkg/archive/tar/reader.go:431: copy(tr.hdrBuff[0:blockSize], zeroBlock[0:blockSize]) copy(tr.hdrBuff[:], zeroBlock)
9 years, 10 months ago (2014-07-02 00:44:28 UTC) #7
dave_cheney.net
https://codereview.appspot.com/108240044/diff/60001/src/pkg/archive/tar/reader.go File src/pkg/archive/tar/reader.go (right): https://codereview.appspot.com/108240044/diff/60001/src/pkg/archive/tar/reader.go#newcode431 src/pkg/archive/tar/reader.go:431: copy(tr.hdrBuff[0:blockSize], zeroBlock[0:blockSize]) On 2014/07/02 00:44:28, dsymonds wrote: > copy(tr.hdrBuff[:], ...
9 years, 10 months ago (2014-07-02 00:49:51 UTC) #8
dsymonds
yep, even better.
9 years, 10 months ago (2014-07-02 00:50:19 UTC) #9
unclejack
I've updated the patch. dsymonds, PTAL On 2014/07/02 00:50:19, dsymonds wrote: > yep, even better.
9 years, 10 months ago (2014-07-02 07:48:25 UTC) #10
unclejack
https://codereview.appspot.com/108240044/diff/40001/src/pkg/archive/tar/reader.go File src/pkg/archive/tar/reader.go (right): https://codereview.appspot.com/108240044/diff/40001/src/pkg/archive/tar/reader.go#newcode36 src/pkg/archive/tar/reader.go:36: hdrBuff []byte // buffer to use in readHeader On ...
9 years, 10 months ago (2014-07-02 08:53:26 UTC) #11
dave_cheney.net
Unclejacksons, i'm happy to commit this change now. Before that happens I need you to ...
9 years, 10 months ago (2014-07-02 10:35:39 UTC) #12
bradfitz
CLA is in. On Wed, Jul 2, 2014 at 3:35 AM, Dave Cheney <dave@cheney.net> wrote: ...
9 years, 10 months ago (2014-07-02 13:49:11 UTC) #13
dsymonds
LGTM
9 years, 10 months ago (2014-07-02 23:38:20 UTC) #14
dsymonds
9 years, 10 months ago (2014-07-02 23:41:32 UTC) #15
*** Submitted as https://code.google.com/p/go/source/detail?r=17404efd6b02 ***

archive/tar: reuse temporary buffer in readHeader

A temporary 512 bytes buffer is allocated for every call to
readHeader. This buffer isn't returned to the caller and it could
be reused to lower the number of memory allocations.

This CL improves it by using a pool and zeroing out the buffer before
putting it back into the pool.

benchmark                  old ns/op     new ns/op     delta
BenchmarkListFiles100k     545249903     538832687     -1.18%

benchmark                  old allocs    new allocs    delta
BenchmarkListFiles100k     2105167       2005692       -4.73%

benchmark                  old bytes     new bytes     delta
BenchmarkListFiles100k     105903472     54831527      -48.22%

This improvement is very important if your code has to deal with a lot
of tarballs which contain a lot of files.

LGTM=dsymonds
R=golang-codereviews, dave, dsymonds, bradfitz
CC=golang-codereviews
https://codereview.appspot.com/108240044

Committer: David Symonds <dsymonds@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b