Bug 90247 - Use StringBuilder in SegmentedString::toString()
Summary: Use StringBuilder in SegmentedString::toString()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-28 21:56 PDT by Kwang Yul Seo
Modified: 2012-06-29 00:07 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.79 KB, patch)
2012-06-28 21:58 PDT, Kwang Yul Seo
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kwang Yul Seo 2012-06-28 21:56:15 PDT
Use a StringBuilder instead of String concatenation because StringBuilder is generally faster.
Comment 1 Kwang Yul Seo 2012-06-28 21:58:59 PDT
Created attachment 150082 [details]
Patch
Comment 2 Adam Barth 2012-06-28 22:33:06 PDT
Comment on attachment 150082 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        Use a StringBuilder instead of String concatenation because StringBuilder is generally faster.
> +        No new tests. Covered by existing tests.

Does this actually make things faster?  If so, by how much?
Comment 3 Kwang Yul Seo 2012-06-28 23:06:29 PDT
(In reply to comment #2)
> (From update of attachment 150082 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=150082&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        Use a StringBuilder instead of String concatenation because StringBuilder is generally faster.
> > +        No new tests. Covered by existing tests.
> 
> Does this actually make things faster?  If so, by how much?

The only caller of SegmentedString::toString is XMLDocumentParser::append(const SegmentedString&). This method retrieves parseString from the argument s as in the following:

void XMLDocumentParser::append(const SegmentedString& s)
{
    String parseString = s.toString();
    ...

    if (m_parserPaused) {
        m_pendingSrc.append(s);
        return;
    }

    ...
}

Because callers of XMLDocumentParser::append usually pass a String, the SegmentedString s usually consists of a single String. In this case, this patch might not improve performance.

However, if the parser is paused, s is appended to m_pendingSrc. When the parser is resumed, m_pendingSrc is appended again. Now we have a SegmentedString with multiple substrings. I guess this patch improves the performance in this case.

I admit this is a micro optimization, so I am not sure if I can measure the performance improvement in a statistically valid method.

If StringBuilder with a single append performs worse than a Single string concatenation, I am skeptical of this being a noticeable improvement
Comment 4 Adam Barth 2012-06-28 23:16:39 PDT
Comment on attachment 150082 [details]
Patch

Ok.  I'm not sure whether this is actually a perf win, but I'm willing to say we should do this on general principles.
Comment 5 WebKit Review Bot 2012-06-29 00:07:01 PDT
Comment on attachment 150082 [details]
Patch

Clearing flags on attachment: 150082

Committed r121523: <http://trac.webkit.org/changeset/121523>
Comment 6 WebKit Review Bot 2012-06-29 00:07:06 PDT
All reviewed patches have been landed.  Closing bug.