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

Issue 2116533005: Optimize StringImpl::find when searching for patterns with length > 1 (Closed)

Created:
4 years, 5 months ago by esprehn
Modified:
3 years, 7 months ago
Reviewers:
CC:
blink-reviews, blink-reviews-wtf_chromium.org, chromium-reviews, Mikhail
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Optimize StringImpl::find when searching for patterns with length > 1 StringImpl::find for any pattern that has a length greater than one uses a running hash algorithm which can be quite expensive when the search string is not present at all, for example when looking for \r characters when doing replace("\r\n", "\n"); We can optimize this case by first looking for the first chararcter since a single letter search is very fast, then starting the search from there. This is not very different from what v8 does in v8/src/string-search.h where they do a single letter scan to find the first letter and then do a naive search several times (at least 10) before switching to a better search algorithm like Boyer-Moore-Horspool. We should consider doing something fancy like that too, but for now lets just start by doing the single letter search at the start. In blink the primary user of find on long strings is actually replacing \r\n with \n anyway, and \r is pretty rare, so this optimization makes sense. Long term we should both consider a better search algorithm like v8 uses and also consider a specialized routine for normalizing new lines. This patch results in a 125% speed up on the DOM/textarea-dom benchmark on my 2013 Mac Pro.

Patch Set 1 #

Patch Set 2 : correct. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+13 lines, -2 lines) Patch
M third_party/WebKit/Source/wtf/text/StringImpl.cpp View 1 1 chunk +13 lines, -2 lines 0 comments Download

Messages

Total messages: 8 (5 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2116533005/1
4 years, 5 months ago (2016-07-02 02:13:11 UTC) #3
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2116533005/20001
4 years, 5 months ago (2016-07-02 02:22:07 UTC) #6
commit-bot: I haz the power
4 years, 5 months ago (2016-07-02 03:37:28 UTC) #8
Dry run: This issue passed the CQ dry run.

Powered by Google App Engine
This is Rietveld 408576698