Bug 18666 - StringImpl::createStrippingNullCharacters has broken optimization
Summary: StringImpl::createStrippingNullCharacters has broken optimization
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-21 13:07 PDT by Mike Belshe
Modified: 2008-04-21 15:17 PDT (History)
2 users (show)

See Also:


Attachments
Patch to StringImpl::createStrippingNullCharacters (1.40 KB, patch)
2008-04-21 13:07 PDT, Mike Belshe
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Belshe 2008-04-21 13:07:02 PDT
I believe a bug was introduced in Change #29470.

The culprit is:
   foundNull |= ~c;      // This is a one's complement

it should be:
   foundNull |= !c;      // if c is 0, then foundNull is true.

The effect is that the optimization in this function doesn't work, and we usually take two passes through the entire string.

I went ahead and wrote a test to optimize further.  My main concern was the copying which is done byte by byte.  I wrote a quick benchmark and tested the conversion of a 10byte string, a 1000 byte string, and a 10000 byte string.  I optimized it, and ran in a loop of 100,000 iterations.  

Results:
                   10B         1000B            10000B 
CURRENT            95ms        1888ms           20409ms
FIXED VERSION      79ms        1051ms           10007ms
FIXED + MEMCPY     75ms         801ms            9125ms

So, simply fixing the bug doubles the performance of this routine for medium and large strings.  Switching to the new algorithm (which I'm attaching) gets another 10%.  Overall, this is negligible on page load performance, however.
Comment 1 Mike Belshe 2008-04-21 13:07:41 PDT
Created attachment 20739 [details]
Patch to StringImpl::createStrippingNullCharacters
Comment 2 Eric Seidel (no email) 2008-04-21 13:16:29 PDT
This looks good to me.  Darin shoudl at least see this change go by.  But the change is r=me.  I can land it with ChangeLog.
Comment 3 Eric Seidel (no email) 2008-04-21 13:18:34 PDT
Comment on attachment 20739 [details]
Patch to StringImpl::createStrippingNullCharacters

This looks good.  Generally changes should have ChangeLogs, using prepare-ChangeLog.  I'll add one and land this.

http://webkit.org/coding/contributing.html  -- talks about the process
Comment 4 Darin Adler 2008-04-21 13:25:16 PDT
Comment on attachment 20739 [details]
Patch to StringImpl::createStrippingNullCharacters

Looks fine to me.
Comment 5 Eric Seidel (no email) 2008-04-21 15:17:02 PDT
Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	WebCore/ChangeLog
	M	WebCore/platform/text/StringImpl.cpp
Committed r32350