Status: New
Owner: ----

New issue 2117 by [email protected]: Concatenating arrays is unnecessarily slow
http://code.google.com/p/v8/issues/detail?id=2117

[via Chrome]
Version: Version 19.0.1084.41 beta
OS: Linux

What steps will reproduce the problem?
1. Run the attached file in Chrome.
2. Look at the dev tool console for speed results.
3. For more info, run the profiler and note how much time we're spending in garbage collection.

This test isn't an artificial microbenchmark; it's boiled down from a real-life use case I ran into this weekend, in which I was merging a bunch of webGL objects into a single triangle list to speed up rendering.

In the slow path, we merge a bunch of arrays into a single array by doing

result = [];
loop:
        result = result.concat(input_array[i])

In the fast path, we build the result in-place:

result = [];
loop:
        [].push.apply(result, input_array[i])

In a test I just ran, the slow path is 5434ms and the fast path is 9ms. It's obvious to a reader that they're equivalent. There's no call out to user-defined code, this is all in a single function, and all the arrays are real javascript Arrays whose properties and prototypes aren't messed with at all. Our optimizer should have all the information it needs to realize that the code is equivalent, and avoid all those extra allocations.


Attachments:
        perf.html  2.6 KB

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to