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

Issue 53340044: code review 53340044: runtime: smarter slice grow (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 5 months ago by dvyukov
Modified:
11 years, 5 months ago
Reviewers:
khr, khr1
CC:
khr, golang-codereviews, iant, rsc
Visibility:
Public.

Description

runtime: smarter slice grow When growing slice take into account size of the allocated memory block. Also apply the same optimization to string->[]byte conversion. Fixes issue 6307. benchmark old ns/op new ns/op delta BenchmarkAppendGrowByte 4541036 4434108 -2.35% BenchmarkAppendGrowString 59885673 44813604 -25.17%

Patch Set 1 #

Patch Set 2 : diff -r 50235ae4e784 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 3 : diff -r 7abe32ccffb1 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 4 : diff -r 7abe32ccffb1 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 5 : diff -r 7abe32ccffb1 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 6

Patch Set 6 : diff -r 94165b19719e https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 7 : diff -r 94165b19719e https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 8 : diff -r fbcb2b86201e https://dvyukov%40google.com@code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+86 lines, -13 lines) Patch
M src/pkg/runtime/append_test.go View 1 2 1 chunk +19 lines, -0 lines 0 comments Download
M src/pkg/runtime/malloc.h View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M src/pkg/runtime/msize.c View 1 2 3 4 5 1 chunk +15 lines, -0 lines 0 comments Download
M src/pkg/runtime/slice.c View 1 2 3 4 5 6 2 chunks +37 lines, -9 lines 0 comments Download
M src/pkg/runtime/string.goc View 1 2 3 4 5 4 chunks +14 lines, -4 lines 0 comments Download

Messages

Total messages: 5
dvyukov
Hello khr@golang.org (cc: golang-codereviews@googlegroups.com, iant@golang.org, rsc@golang.org), I'd like you to review this change to https://dvyukov%40google.com@code.google.com/p/go/
11 years, 5 months ago (2014-01-23 14:52:54 UTC) #1
khr
LGTM. https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/msize.c File src/pkg/runtime/msize.c (right): https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/msize.c#newcode176 src/pkg/runtime/msize.c:176: return ROUND(size, PageSize); The ROUND may wrap around ...
11 years, 5 months ago (2014-01-24 21:59:09 UTC) #2
dvyukov
https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/msize.c File src/pkg/runtime/msize.c (right): https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/msize.c#newcode176 src/pkg/runtime/msize.c:176: return ROUND(size, PageSize); On 2014/01/24 21:59:09, khr wrote: > ...
11 years, 5 months ago (2014-01-27 10:19:39 UTC) #3
dvyukov
*** Submitted as https://code.google.com/p/go/source/detail?r=a41f8780d8b0 *** runtime: smarter slice grow When growing slice take into account ...
11 years, 5 months ago (2014-01-27 11:11:30 UTC) #4
khr1
11 years, 5 months ago (2014-01-27 18:12:07 UTC) #5
On Mon, Jan 27, 2014 at 2:19 AM, <dvyukov@google.com> wrote:

>
> https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/msize.c
> File src/pkg/runtime/msize.c (right):
>
> https://codereview.appspot.com/53340044/diff/80001/src/
> pkg/runtime/msize.c#newcode176
> src/pkg/runtime/msize.c:176: return ROUND(size, PageSize);
> On 2014/01/24 21:59:09, khr wrote:
>
>> The ROUND may wrap around to 0.  You should check for that (unless you
>>
> have an
>
>> argument for why it can't happen).
>>
>
> added the check for overflow
>
>
> https://codereview.appspot.com/53340044/diff/80001/src/pkg/runtime/slice.c
> File src/pkg/runtime/slice.c (right):
>
> https://codereview.appspot.com/53340044/diff/80001/src/
> pkg/runtime/slice.c#newcode129
> src/pkg/runtime/slice.c:129: ret->len = x.len;
> On 2014/01/24 21:59:09, khr wrote:
>
>> Add a comment here that no GC-triggering operations are allowed until
>>
> the
>
>> memmove/memclr happen.
>>
>
> I've added m->locks++/-- and a comment.
>
>
> https://codereview.appspot.com/53340044/diff/80001/src/
> pkg/runtime/string.goc
> File src/pkg/runtime/string.goc (right):
>
> https://codereview.appspot.com/53340044/diff/80001/src/
> pkg/runtime/string.goc#newcode292
> src/pkg/runtime/string.goc:292: runtime·memclr(b.array+b.len,
> cap-b.len);
> On 2014/01/24 21:59:09, khr wrote:
>
>> Do we need this?
>> Maybe it is a security issue to disallow reading of some other old
>>
> object.
>
> We are returning the slice with capacity larger than len. If you are
> reslice it to increase capacity, you must read zeroes there. Just as
> for:
> a := make([]byte, 0, 100)
> a = a[0:100]
> a must be all zeroes
>
>
Ok, makes sense.


> https://codereview.appspot.com/53340044/
>
Sign in to reply to this message.

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