Bug 30436 - fast/css/large-list-of-rules-crash.html concatenates strings in an inefficient way
Summary: fast/css/large-list-of-rules-crash.html concatenates strings in an inefficien...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-16 02:33 PDT by Yuta Kitamura
Modified: 2009-10-18 00:26 PDT (History)
2 users (show)

See Also:


Attachments
Fix inefficient string concatenation. (2.07 KB, patch)
2009-10-16 02:38 PDT, Yuta Kitamura
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yuta Kitamura 2009-10-16 02:33:32 PDT
LayoutTest/fast/css/large-list-of-rules-crash.html contains JavaScript code that repeatedly concatenates strings in an inefficient way. Concatenation of strings should be done using Array.join method.
Comment 1 Yuta Kitamura 2009-10-16 02:38:49 PDT
Created attachment 41279 [details]
Fix inefficient string concatenation.
Comment 2 Mark Rowe (bdash) 2009-10-16 03:11:30 PDT
Can you please explain why this change is necessary?  In my measurements with TOT WebKit there’s approximately 10ms of difference between the two approaches, accounting for less than 2% of the execution time of this test.
Comment 3 Yuta Kitamura 2009-10-17 22:45:11 PDT
(In reply to comment #2)
> Can you please explain why this change is necessary?  In my measurements with
> TOT WebKit there’s approximately 10ms of difference between the two approaches,
> accounting for less than 2% of the execution time of this test.

Yes, as for JavaScriptCore, only small improvement can be observed. However, currently debug version of V8 is hitting this problem and consuming test cycles.

I admit the argument above is weak..., but I believe there is no need to leave an inefficient test as is.
Comment 4 Mark Rowe (bdash) 2009-10-17 22:46:34 PDT
It’d be stronger if you took a few seconds to provide data to support your claim that it is inefficient.
Comment 5 Yuta Kitamura 2009-10-17 22:57:45 PDT
(In reply to comment #4)
> It’d be stronger if you took a few seconds to provide data to support your
> claim that it is inefficient.

Original code look like this:
    var s = "";
    for (i = 0 ; i < 200000 ; i++) {
        s += "a {}\n";
    }

This code produces potentially (especially for debug binary) allocation of 200000 string objects with length of 5, 10, 15, ..., 5*200000. The fixed version does not require the intermediate string objects.

I believe using Array.join is the common pattern to avoid unneeded allocation.
Comment 6 Mark Rowe (bdash) 2009-10-17 23:02:46 PDT
You’ve just restated what the patch does.  I’m interested in specifics about how much of an improvement this change is.
Comment 7 Yuta Kitamura 2009-10-17 23:13:29 PDT
(In reply to comment #6)
> You’ve just restated what the patch does.  I’m interested in specifics about
> how much of an improvement this change is.

From 30sec to 3sec, as for V8 debug.
Comment 8 Mark Rowe (bdash) 2009-10-17 23:15:14 PDT
Thanks!
Comment 9 WebKit Commit Bot 2009-10-17 23:27:24 PDT
Comment on attachment 41279 [details]
Fix inefficient string concatenation.

Clearing flags on attachment: 41279

Committed r49748: <http://trac.webkit.org/changeset/49748>
Comment 10 WebKit Commit Bot 2009-10-17 23:27:27 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Yuta Kitamura 2009-10-18 00:26:05 PDT
Thanks!