Bug 83968 - Add a version of StringImpl::find() without offset
Summary: Add a version of StringImpl::find() without offset
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on: 83961
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-13 19:21 PDT by Benjamin Poulain
Modified: 2012-04-25 22:46 PDT (History)
6 users (show)

See Also:


Attachments
Patch (13.50 KB, patch)
2012-04-13 20:18 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ec2-cr-linux-04 (6.40 MB, application/zip)
2012-04-14 00:33 PDT, WebKit Review Bot
no flags Details
Archive of layout-test-results from ec2-cr-linux-02 (6.58 MB, application/zip)
2012-04-14 01:34 PDT, WebKit Review Bot
no flags Details
Patch for landing (12.86 KB, patch)
2012-04-24 17:08 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (14.71 KB, patch)
2012-04-24 17:50 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ec2-cr-linux-03 (6.09 MB, application/zip)
2012-04-25 05:13 PDT, WebKit Review Bot
no flags Details
Patch (15.57 KB, patch)
2012-04-25 15:48 PDT, Benjamin Poulain
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2012-04-13 19:21:57 PDT
Since the function is not inline, the offset forces a bunch of extra operations.
Comment 1 Benjamin Poulain 2012-04-13 20:18:20 PDT
Created attachment 137194 [details]
Patch
Comment 2 Benjamin Poulain 2012-04-13 20:19:31 PDT
This is on top of https://bugs.webkit.org/show_bug.cgi?id=83961
You can ignore the bots.
Comment 3 Build Bot 2012-04-13 20:50:12 PDT
Comment on attachment 137194 [details]
Patch

Attachment 137194 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/12400330
Comment 4 WebKit Review Bot 2012-04-14 00:33:21 PDT
Comment on attachment 137194 [details]
Patch

Attachment 137194 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/12406194

New failing tests:
fast/xpath/substring-after.html
fast/xpath/4XPath/Core/test_core_functions.html
Comment 5 WebKit Review Bot 2012-04-14 00:33:27 PDT
Created attachment 137199 [details]
Archive of layout-test-results from ec2-cr-linux-04

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: ec2-cr-linux-04  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.35-28-virtual-x86_64-with-Ubuntu-10.10-maverick
Comment 6 WebKit Review Bot 2012-04-14 01:34:04 PDT
Comment on attachment 137194 [details]
Patch

Attachment 137194 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/12408122

New failing tests:
fast/xpath/substring-after.html
fast/xpath/4XPath/Core/test_core_functions.html
Comment 7 WebKit Review Bot 2012-04-14 01:34:10 PDT
Created attachment 137200 [details]
Archive of layout-test-results from ec2-cr-linux-02

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: ec2-cr-linux-02  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.35-28-virtual-x86_64-with-Ubuntu-10.10-maverick
Comment 8 Sam Weinig 2012-04-15 16:13:27 PDT
Comment on attachment 137194 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=137194&action=review

> Source/JavaScriptCore/ChangeLog:11
> +        This gives a 12% gains for strings of distribution of strings between 30 and 100 characters.

I don't completely understand this sentence.

> Source/WTF/ChangeLog:11
> +        By not havig the index, we can skip a couple of branches and a few instructions. This gives

Typo: havig -> having.

> Source/WTF/ChangeLog:14
> +        The case of empty string is moved bellow (matchLength == 1) since it is a less common operation.

Typo: bellow -> below.  

How did you determine that finding on the empty string is less common?

> Source/WTF/wtf/text/StringImpl.cpp:901
> +    // Check for null or empty string to match against
> +    if (UNLIKELY(!matchString))
> +        return notFound;

I don't think this checks for empty strings.
Comment 9 Benjamin Poulain 2012-04-15 19:09:34 PDT
Thanks for the review. Sorry I butchered that ChangeLog.

> > Source/WTF/ChangeLog:14
> > +        The case of empty string is moved bellow (matchLength == 1) since it is a less common operation.
> 
> How did you determine that finding on the empty string is less common?

It is actually just an assumption. The case of length==1 is pretty common from JavaScript.
Comment 10 Benjamin Poulain 2012-04-24 17:08:48 PDT
Created attachment 138695 [details]
Patch for landing
Comment 11 Darin Adler 2012-04-24 17:31:48 PDT
Comment on attachment 138695 [details]
Patch for landing

View in context: https://bugs.webkit.org/attachment.cgi?id=138695&action=review

> Source/JavaScriptCore/runtime/StringPrototype.cpp:781
> +        if (pos)
> +            result = s.find(u2, pos);
> +        else
> +            result = s.find(u2);

I don’t get how this could be an improvement. Can’t the normal find just optimize just as well for the case where pos is 0 as an if statement can?
Comment 12 Benjamin Poulain 2012-04-24 17:50:44 PDT
Created attachment 138704 [details]
Patch
Comment 13 Benjamin Poulain 2012-04-24 17:58:28 PDT
> > Source/JavaScriptCore/runtime/StringPrototype.cpp:781
> > +        if (pos)
> > +            result = s.find(u2, pos);
> > +        else
> > +            result = s.find(u2);
> 
> I don’t get how this could be an improvement. Can’t the normal find just optimize just as well for the case where pos is 0 as an if statement can?

Yep, I was divided on that one...

It was showing improvement on JavaScript because the source strings are big enough on average. I did not want to risk slowing down something else with the extra branch and function call.

Since you also think that does not look great, I removed that from the latest version. I can change this later if needed.
Comment 14 Benjamin Poulain 2012-04-24 18:05:54 PDT
Comment on attachment 138704 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=138704&action=review

> Source/JavaScriptCore/runtime/StringPrototype.cpp:764
>      if (a1.isUndefined())
> -        pos = 0;
> -    else if (a1.isUInt32())
> -        pos = min<uint32_t>(a1.asUInt32(), len);
> +        result = s.find(u2);

This is the best case for this patch, and it is also very common, so I am fine sticking with this.
Comment 15 Benjamin Poulain 2012-04-24 19:24:59 PDT
Finally solved the symbol issue. Sam, would you mind looking at the changes and confirm it is still ok to land:
-removed the if(pos==0) following Darin comment
-added the new symbol for WebKit2 Windows
Comment 16 WebKit Review Bot 2012-04-25 05:13:34 PDT
Comment on attachment 138704 [details]
Patch

Attachment 138704 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/12535242

New failing tests:
fast/xpath/substring-after.html
fast/xpath/4XPath/Core/test_core_functions.html
Comment 17 WebKit Review Bot 2012-04-25 05:13:41 PDT
Created attachment 138787 [details]
Archive of layout-test-results from ec2-cr-linux-03

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: ec2-cr-linux-03  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.35-28-virtual-x86_64-with-Ubuntu-10.10-maverick
Comment 18 Benjamin Poulain 2012-04-25 15:48:19 PDT
Created attachment 138885 [details]
Patch
Comment 19 Benjamin Poulain 2012-04-25 22:31:05 PDT
Committed r115290: <http://trac.webkit.org/changeset/115290>
Comment 20 Csaba Osztrogonác 2012-04-25 22:34:56 PDT
Reopen, because http://trac.webkit.org/changeset/115290 broke the Qt Mac build.
Bot unfortunately I can't paste build log, because build.webkit.org is died at the moment.
Comment 21 Csaba Osztrogonác 2012-04-25 22:37:49 PDT
build.webkit.org works again, so here is the build log:
../../../../Source/WebCore/bridge/qt/qt_runtime.cpp: In function ‘bool JSC::Bindings::isJSUint8ClampedArray(JSC::JSValue)’:
../../../../Source/WebCore/bridge/qt/qt_runtime.cpp:142: error: ‘JSUint8ClampedArray’ is not a class or namespace
Comment 22 Csaba Osztrogonác 2012-04-25 22:46:03 PDT
Sorry for blaming this patch, it is absolutely innocent. :)