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

Issue 7432050: code review 7432050: strings: Optimized Replace to be 2x faster. (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 2 months ago by Ewan Chou
Modified:
10 years, 10 months ago
Reviewers:
golang-dev, rsc, bradfitz
CC:
golang-dev
Visibility:
Public.

Description

strings: Optimized Replace to be 2x faster. The main idea is to avoid replace count calculation. If len(old) <= len(new) , we make a string with 0 length and a cap of len(s), otherwise we make a string with 0 length and a cap of len(s)*1.5. The downside is a small proportion of memory will be wasted. but if the len(old) == len(new), there would be no tradeoff at all. benchmark old ns/op new ns/op delta BenchmarkByteByteReplaces 8480 1364 -83.92% BenchmarkReplaceByteByte 10015 3806 -62.00% BenchmarkReplaceDefault 13495 7356 -45.49% BenchmarkReplaceOldEmpty 101105 45022 -55.47% benchmark old MB/s new MB/s speedup BenchmarkReplaceByteByte 149.77 394.09 2.63x BenchmarkReplaceDefault 111.15 203.90 1.83x BenchmarkReplaceOldEmpty 14.84 33.32 2.25x

Patch Set 1 #

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

Unified diffs Side-by-side diffs Delta from patch set Stats (+77 lines, -24 lines) Patch
M src/pkg/strings/strings.go View 1 1 chunk +53 lines, -24 lines 0 comments Download
M src/pkg/strings/strings_test.go View 1 1 chunk +24 lines, -0 lines 0 comments Download

Messages

Total messages: 13
Ewan Chou
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com, rsc@golang.org), I'd like you to review this change to https://code.google.com/p/go
11 years, 2 months ago (2013-03-03 08:41:53 UTC) #1
bradfitz
https://codereview.appspot.com/7432050/diff/18001/src/pkg/strings/strings.go File src/pkg/strings/strings.go (right): https://codereview.appspot.com/7432050/diff/18001/src/pkg/strings/strings.go#newcode644 src/pkg/strings/strings.go:644: func Replace(s, old, new string, n int) string { ...
11 years, 2 months ago (2013-03-03 17:00:28 UTC) #2
Ewan Chou
On 2013/03/03 17:00:28, bradfitz wrote: > https://codereview.appspot.com/7432050/diff/18001/src/pkg/strings/strings.go > File src/pkg/strings/strings.go (right): > > https://codereview.appspot.com/7432050/diff/18001/src/pkg/strings/strings.go#newcode644 > ...
11 years, 2 months ago (2013-03-04 01:12:48 UTC) #3
bradfitz
I'm afraid it's probably a little too close to Go 1.1's release right now to ...
11 years, 2 months ago (2013-03-04 01:27:18 UTC) #4
Ewan Chou
On 2013/03/04 01:12:48, Ewan Chou wrote: > On 2013/03/03 17:00:28, bradfitz wrote: > > https://codereview.appspot.com/7432050/diff/18001/src/pkg/strings/strings.go ...
11 years, 2 months ago (2013-03-04 01:28:02 UTC) #5
rsc
I agree with Brad. I appreciate the effort, but it's too late to be rewriting ...
11 years, 2 months ago (2013-03-04 15:28:06 UTC) #6
bradfitz
Q=wait Ewan, did you still want to get this in?
10 years, 10 months ago (2013-06-17 21:19:35 UTC) #7
Ewan Chou
On 2013/06/17 21:19:35, bradfitz wrote: > Q=wait > > Ewan, did you still want to ...
10 years, 10 months ago (2013-06-17 23:34:50 UTC) #8
bradfitz
I think this is starting to overlap too much with strings.NewReplacer and its selection of ...
10 years, 10 months ago (2013-06-21 20:29:49 UTC) #9
bradfitz
Q=wait
10 years, 10 months ago (2013-06-21 20:30:05 UTC) #10
Ewan Chou
On 2013/06/21 20:30:05, bradfitz wrote: > Q=wait OK, I understand, but there would be no ...
10 years, 10 months ago (2013-06-22 00:58:38 UTC) #11
rsc
Please drop this CL. This is not important enough to be worth the complexity of ...
10 years, 10 months ago (2013-07-02 00:52:38 UTC) #12
Ewan Chou
10 years, 10 months ago (2013-07-02 02:21:26 UTC) #13
On 2013/07/02 00:52:38, rsc wrote:
> Please drop this CL. This is not important enough to be worth the complexity
of
> maintaining more code.

Yes, it is a little too complex.
Dropped.
Sign in to reply to this message.

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