Chromium Code Reviews
DescriptionOptimize 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. #Messages
Total messages: 8 (5 generated)
|