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

Issue 1231673008: Optimize String.prototype.includes (Closed)

Created:
5 years, 5 months ago by Dan Ehrenberg
Modified:
5 years, 5 months ago
Reviewers:
adamk, thefourtheye_
CC:
v8-dev
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

Optimize String.prototype.includes This patch removes the MathMax call from String.prototype.includes in order to improve performance. With some quick and dirty benchmarking, (test case courtesy of the node folks) a sizable performance gain is visible: d8> function testIndexOf() { var stringArray = [ 'hello', 'world', '123', 'abc' ]; return stringArray.some(function(val, idx, arr) { return val.indexOf('world') !== -1 })} d8> function testIncludes() { var stringArray = [ 'hello', 'world', '123', 'abc' ]; return stringArray.some(function(val, idx, arr) { return val.includes('world') })} d8> function testTime(fn) { var before = Date.now(); fn(); return Date.now() - before; } d8> testTime(function() { for (var i = 0; i < 10000000; i++) { testIncludes() } }) 2244 d8> testTime(function() { for (var i = 0; i < 10000000; i++) { testIndexOf() } }) 2212 Compare that to before the test, when the performance difference was much larger: d8> testTime(function() { for (var i = 0; i < 10000000; i++) { testIndexOf() } }) 2223 d8> testTime(function() { for (var i = 0; i < 10000000; i++) { testIncludes() } }) 2650 In my runs, performance of both functions drifts up and down, but running them in quick succession back and forth shows a roughly consistent delta of about this magnitude. String.prototype.includes is still slightly (maybe 5%) slower than String.prototype.indexOf, but the effect is significantly reduced. R=adamk BUG=v8:3807 LOG=Y Committed: https://crrev.com/d20a5090428e9abaa9e994cca7468955666fd24f Cr-Commit-Position: refs/heads/master@{#29665}

Patch Set 1 #

Total comments: 4

Patch Set 2 : Changes from Adam's review #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+10 lines, -8 lines) Patch
M src/string.js View 1 1 chunk +10 lines, -8 lines 2 comments Download

Messages

Total messages: 10 (2 generated)
Dan Ehrenberg
This patch is basically a rebase of https://codereview.chromium.org/832713009 .
5 years, 5 months ago (2015-07-14 22:24:50 UTC) #1
adamk
Can you re-run these benchmarks with the s/$toInteger/TO_INTEGER/ change and update the CL description if ...
5 years, 5 months ago (2015-07-14 23:24:55 UTC) #2
Dan Ehrenberg
https://codereview.chromium.org/1231673008/diff/1/src/string.js File src/string.js (right): https://codereview.chromium.org/1231673008/diff/1/src/string.js#newcode1040 src/string.js:1040: var searchString = TO_STRING_INLINE(searchString); On 2015/07/14 23:24:55, adamk wrote: ...
5 years, 5 months ago (2015-07-14 23:45:48 UTC) #3
adamk
lgtm
5 years, 5 months ago (2015-07-14 23:48:28 UTC) #4
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1231673008/20001
5 years, 5 months ago (2015-07-15 00:02:07 UTC) #6
commit-bot: I haz the power
Committed patchset #2 (id:20001)
5 years, 5 months ago (2015-07-15 01:01:46 UTC) #7
commit-bot: I haz the power
Patchset 2 (id:??) landed as https://crrev.com/d20a5090428e9abaa9e994cca7468955666fd24f Cr-Commit-Position: refs/heads/master@{#29665}
5 years, 5 months ago (2015-07-15 01:02:06 UTC) #8
thefourtheye_
5 years, 5 months ago (2015-07-15 01:26:00 UTC) #10
Message was sent while issue was closed.
https://codereview.chromium.org/1231673008/diff/20001/src/string.js
File src/string.js (right):

https://codereview.chromium.org/1231673008/diff/20001/src/string.js#newcode1040
src/string.js:1040: searchString = TO_STRING_INLINE(searchString);
Isn't this a DEOPT? Using the argument variable in both sides of an assignment
expression?

https://codereview.chromium.org/1231673008/diff/20001/src/string.js#newcode1050
src/string.js:1050: var searchStringLength = searchString.length;
Very minor optimization, but can we move this above and return true if it is
zero?

Powered by Google App Engine
This is Rietveld 408576698