Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Issue 401783003: Optimize algorithm for String.prototype.repeat(), fix value caching in others (Closed)

Created:
6 years, 5 months ago by impinball
Modified:
6 years, 2 months ago
CC:
v8-dev
Project:
v8
Visibility:
Public.

Description

Optimize algorithm for String.prototype.repeat(), fix value caching in others 1. Optimize algorithm for String.prototype.repeat() to O(log N). 2. Improve variable caching usage for the following String instance methods: - String.prototype.startsWith() - String.prototype.endsWith() - String.prototype.contains() - String.prototype.substr() The second part made minor improvements across the board, although only usually by a couple milliseconds per million reps with normal cases. I benchmarked these improvements (and checked for improvement) with roughly this general piece of code, running under both the main version and my edits. var MAX_ITERATIONS = 1000000 var string = 'something'; var start = +(new Date()); for (var i = 0; i < MAX_ITERATIONS; i++) { string.someMethod(args); } var end = new Date().getTime(); print('Time taken: ' + (end - start) + ' ms'); See V8 bug #3450 for details (https://code.google.com/p/v8/issues/detail?id=3450). R=mstarzinger@chromium.org

Patch Set 1 #

Total comments: 5

Patch Set 2 : Clarify with comments #

Total comments: 3

Patch Set 3 : Remove some small edits #

Patch Set 4 : Make return string less cons-y #

Patch Set 5 : Replace bitwise with arithmetic operators #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+21 lines, -8 lines) Patch
M AUTHORS View 1 chunk +1 line, -0 lines 0 comments Download
M src/harmony-string.js View 1 2 3 4 3 chunks +20 lines, -8 lines 3 comments Download

Messages

Total messages: 19 (0 generated)
impinball
6 years, 5 months ago (2014-07-20 01:56:18 UTC) #1
Michael Starzinger
https://codereview.chromium.org/401783003/diff/1/AUTHORS File AUTHORS (right): https://codereview.chromium.org/401783003/diff/1/AUTHORS#newcode37 AUTHORS:37: Isiah Meadows <impinball@gmail.com> Did you already sign the CLA. ...
6 years, 4 months ago (2014-07-28 11:13:52 UTC) #2
impinball
On 2014/07/28 11:13:52, Michael Starzinger wrote: > https://codereview.chromium.org/401783003/diff/1/AUTHORS > File AUTHORS (right): > > https://codereview.chromium.org/401783003/diff/1/AUTHORS#newcode37 ...
6 years, 4 months ago (2014-07-30 04:02:42 UTC) #3
impinball
On 2014/07/30 04:02:42, impinball wrote: > On 2014/07/28 11:13:52, Michael Starzinger wrote: > > https://codereview.chromium.org/401783003/diff/1/AUTHORS ...
6 years, 4 months ago (2014-07-30 04:08:39 UTC) #4
impinball
On 2014/07/30 04:08:39, impinball wrote: > On 2014/07/30 04:02:42, impinball wrote: > > On 2014/07/28 ...
6 years, 4 months ago (2014-07-30 04:43:20 UTC) #5
Michael Starzinger
> https://codereview.chromium.org/401783003/diff/1/src/harmony-string.js#newcode34 > > > > src/harmony-string.js:34: return res + s; > > > > ...
6 years, 4 months ago (2014-07-30 08:52:22 UTC) #6
aandrey
https://codereview.chromium.org/401783003/diff/20001/src/harmony-string.js File src/harmony-string.js (right): https://codereview.chromium.org/401783003/diff/20001/src/harmony-string.js#newcode26 src/harmony-string.js:26: if (n < 1) return ''; nit: use "" ...
6 years, 4 months ago (2014-07-30 09:04:01 UTC) #7
impinball
On 2014/07/30 08:52:22, Michael Starzinger wrote: > [removed for brevity] > Do you have numbers ...
6 years, 4 months ago (2014-07-31 10:03:01 UTC) #8
impinball
On 2014/07/30 09:04:01, aandrey wrote: > https://codereview.chromium.org/401783003/diff/20001/src/harmony-string.js > File src/harmony-string.js (right): > > https://codereview.chromium.org/401783003/diff/20001/src/harmony-string.js#newcode26 > ...
6 years, 4 months ago (2014-07-31 10:11:22 UTC) #9
Vyacheslav Egorov (Google)
DBC on the benchmarking side One important difference is that %StringBuilderConcat builds Sequential string while ...
6 years, 4 months ago (2014-08-07 12:10:25 UTC) #10
impinball
@Vyacheslav Egorov I tried using %StringBuilderConcat with this macro: macro APPEND_INTERNAL_ARRAY(dest, src, array) array[0] = ...
6 years, 4 months ago (2014-08-08 08:46:04 UTC) #11
caitp (gmail)
If `s` is the empty string, iterating 2^31-1 times won't alter the output --- so ...
6 years, 4 months ago (2014-08-13 13:38:45 UTC) #12
caitp (gmail)
On 2014/08/13 13:38:45, caitp wrote: > If `s` is the empty string, iterating 2^31-1 times ...
6 years, 4 months ago (2014-08-13 13:56:02 UTC) #13
Michael Starzinger
I am handing off the final decision of whether we want to land this change ...
6 years, 4 months ago (2014-08-13 14:21:17 UTC) #14
caitp (gmail)
Whether the perf fixes are wanted or not, this CL does at the very least ...
6 years, 4 months ago (2014-08-15 17:54:18 UTC) #15
impinball
@All It should now actually follow the standard now that I replaced the bitwise operators ...
6 years, 4 months ago (2014-08-16 10:48:07 UTC) #16
Yang
Please add test cases for cases specific to this impelementation, like for n = 2^m-1, ...
6 years, 4 months ago (2014-08-19 12:29:00 UTC) #17
Yang
On 2014/08/19 12:29:00, Yang wrote: > Please add test cases for cases specific to this ...
6 years, 3 months ago (2014-09-22 15:29:55 UTC) #18
Yang
6 years, 2 months ago (2014-10-17 10:02:09 UTC) #19
On 2014/09/22 15:29:55, Yang wrote:
> On 2014/08/19 12:29:00, Yang wrote:
> > Please add test cases for cases specific to this impelementation, like for n
=
> > 2^m-1, etc.
> > 
> > Also, please sign the CLA:
> > https://developers.google.com/open-source/cla/individual?csw=1
> > 
> > https://codereview.chromium.org/401783003/diff/80001/src/harmony-string.js
> > File src/harmony-string.js (right):
> > 
> >
>
https://codereview.chromium.org/401783003/diff/80001/src/harmony-string.js#ne...
> > src/harmony-string.js:31: if (n % 2) res += s;
> > two-character indent please.
> > 
> >
>
https://codereview.chromium.org/401783003/diff/80001/src/harmony-string.js#ne...
> > src/harmony-string.js:36: // unroll last iteration, no need to double the
> > initial string again at the
> > Capitalize "unroll".
> > 
> >
>
https://codereview.chromium.org/401783003/diff/80001/src/harmony-string.js#ne...
> > src/harmony-string.js:43: return %StringBuilderConcat(array, 1, "");
> > Use %FlattenString
> 
> Just to be clear, I followed up on the CLA thing. Everything is fine in that
> regard. I'm just waiting for you to address the remaining issues so that I can
> land this.

Closing this since I landed https://codereview.chromium.org/657863002/

Powered by Google App Engine
This is Rietveld 408576698