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

Issue 8164043: code review 8164043: bytes: don't grow Buffer if capacity is available (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 11 months ago by bradfitz
Modified:
11 years, 11 months ago
Reviewers:
khr1, robryk
CC:
golang-dev, r, gri
Visibility:
Public.

Description

bytes: don't grow Buffer if capacity is available Also added a new benchmark from the same test: benchmark old ns/op new ns/op delta BenchmarkBufferNotEmptyWriteRead 2643698 709189 -73.17% Fixes Issue 5154

Patch Set 1 #

Patch Set 2 : diff -r a3717460e37c https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r a3717460e37c https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 4 : diff -r a3717460e37c https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r e5ff184d8a45 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+41 lines, -0 lines) Patch
M src/pkg/bytes/buffer.go View 1 1 chunk +5 lines, -0 lines 0 comments Download
M src/pkg/bytes/buffer_test.go View 1 2 3 1 chunk +32 lines, -0 lines 0 comments Download
M src/pkg/bytes/export_test.go View 1 2 3 1 chunk +4 lines, -0 lines 0 comments Download

Messages

Total messages: 11
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 11 months ago (2013-03-29 18:22:42 UTC) #1
r
LGTM https://codereview.appspot.com/8164043/diff/5001/src/pkg/bytes/export_test.go File src/pkg/bytes/export_test.go (right): https://codereview.appspot.com/8164043/diff/5001/src/pkg/bytes/export_test.go#newcode13 src/pkg/bytes/export_test.go:13: } func (b *Buffer) Cap() int { return ...
11 years, 11 months ago (2013-03-29 18:27:49 UTC) #2
r
let gri have a look too before you submit. there may be a prettier way ...
11 years, 11 months ago (2013-03-29 18:28:34 UTC) #3
bradfitz
Hello golang-dev@googlegroups.com, r@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 11 months ago (2013-03-29 18:30:35 UTC) #4
bradfitz
https://codereview.appspot.com/8164043/diff/5001/src/pkg/bytes/export_test.go File src/pkg/bytes/export_test.go (right): https://codereview.appspot.com/8164043/diff/5001/src/pkg/bytes/export_test.go#newcode13 src/pkg/bytes/export_test.go:13: } On 2013/03/29 18:27:49, r wrote: > func (b ...
11 years, 11 months ago (2013-03-29 18:30:37 UTC) #5
gri
LGTM nice!
11 years, 11 months ago (2013-03-29 19:26:02 UTC) #6
bradfitz
*** Submitted as https://code.google.com/p/go/source/detail?r=7b47ca7337ca *** bytes: don't grow Buffer if capacity is available Also added ...
11 years, 11 months ago (2013-03-29 19:39:25 UTC) #7
khr1
I would think you'd want to make sure that you weren't copying too much. If ...
11 years, 11 months ago (2013-03-29 19:47:49 UTC) #8
bradfitz
Yeah, that was my hesitation before too, and I just realized after submitting that the ...
11 years, 11 months ago (2013-03-29 19:51:53 UTC) #9
robryk
> On Fri, Mar 29, 2013 at 12:47 PM, Keith Randall <mailto:khr@google.com> wrote: > > ...
11 years, 11 months ago (2013-03-29 20:03:23 UTC) #10
bradfitz
11 years, 11 months ago (2013-03-29 20:04:59 UTC) #11
On Fri, Mar 29, 2013 at 1:03 PM, <robryk@gmail.com> wrote:

> On Fri, Mar 29, 2013 at 12:47 PM, Keith Randall
>>
> <mailto:khr@google.com> wrote:
>
>  > I would think you'd want to make sure that you weren't copying too
>>
> much.
>
>> >  If you're asking for one byte and there's one byte available at the
>>
> start
>
>> > of the buffer, you probably don't want to copy down N bytes only to
>>
> free up
>
>> > that one byte at the end.  Better to grow the buffer now so that
>>
> next time
>
>> > there is more space.
>> >
>> > So copy if the buffer is at least half empty?  Something like "m+n
>>
> <=
>
>> > cap(b.buf) && m <= cap(b.buf)/2"
>>
>
> m+n <= cap(b.buf)/2 should be ok: we will then rewrite every byte
> inserted into the buffer at most once (we will only copy bytes from its
> second half into its first half; and it never shrinks) and we will grow
> the buffer to at most twice the size required.
>

yeah, that's what I went with in https://codereview.appspot.com/8173043/
Sign in to reply to this message.

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