Array.prototype.splice() becomes a lot slower.
Reported by
s.pa...@gmail.com,
Jun 9 2016
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.24 Safari/537.36 Steps to reproduce the problem: 1. I have observed this slowness when I use splice to clear a huge array e.g. an array containing pixel data ~ 2 million items. 2. To reproduce the issue, you can create a dummy array of 2 million integers inside and use splice to clear the array (e.g. aBigArray.splice(0,aBigArray.length) 3. In my machine, it takes ~16ms for such an array while it takes ~7ms in IE11. In my real application setup it takes about 7seconds to clear a big array using splice. This is a serious issue for my web app. 4. This issue has occurred since Chrome 51. What is the expected behavior? splice in Chrome 51 should not be slower than in Chrome 50.. and should not be slower than in IE11. What went wrong? splice is too slow when removing an entire big array. Did this work before? Yes before updating to Chrome51.. say chrome50. Chrome version: 51 Channel: n/a OS Version: 6.1 (Windows 7, Windows Server 2008 R2) Flash Version: Shockwave Flash 22.0 r0 will you fix it?
,
Jun 10 2016
,
Dec 19 2016
We are also seeing performance issues with .splice. Visit https://user.sitepen.com/~nroberts/gfx.html, click “Create Circles” then click “Remove & Add Circles”. This performance impact can be negated simply by performing a .splice call with a third argument (an object to be inserted into the array). Once this is done, normal .splice use may be resumed without performance issues. You may see this speed improvement in effect by visiting the same page with a flag set (https://user.sitepen.com/~nroberts/gfx.html?fixSplice). We had to do a very specific sequence of operations in this exact order to restore the speed of a .splice operation: * Do a normal .splice (view https://user.sitepen.com/~nroberts/gfx.html?fixSplice&skipStep=splice to see what happens when this is not true) * Call .push (view https://user.sitepen.com/~nroberts/gfx.html?fixSplice&skipStep=push to see what happens when this is not true) * Perform a no-op .splice where we insert a single object while removing a single object (view https://user.sitepen.com/~nroberts/gfx.html?fixSplice&skipStep=noop to see what happens when this is not true) In addition, manually downshifting elements in the array to remove an item results in a speed improvement even beyond splice: https://user.sitepen.com/~nroberts/gfx.html?customSplice Finally, if you visit the page as normal (https://user.sitepen.com/~nroberts/gfx.html) click “Create Circles” then click “Remove & Add Circles” then, in the console, set the global `recreateChildren = true` then click “Remove & Add Circles” again, this will recreate the internal array and also results in a speed improvement.
,
Jul 14 2017
,
Jul 14 2017
cbruni@ please take a look (might have been resolved by now).
,
Aug 17 2017
https://user.sitepen.com/~nroberts/gfx.html?fixSplice: Elapsed time: 6778.52 splicing: 6449.98 gfx.js:93 [ removeAndAddCircles ]: Num shapes = 4000 https://user.sitepen.com/~nroberts/gfx.html: Elapsed time: 6743.22 splicing: 6394.22 gfx.js:93 [ removeAndAddCircles ]: Num shapes = 4000 https://user.sitepen.com/~nroberts/gfx.html: (recreateChildren = true) gfx.js:32 Elapsed time: 589.78 splicing: 260.77 gfx.js:93 [ removeAndAddCircles ]: Num shapes = 4000 At least on the demo page that seems to be working now. a = new Array(10000000); console.time(); a.splice(0, a.length); console.timeEnd() However is still rather slow 165ms.
,
Aug 17 2017
Wait, that seems to be only the case on the gfx website, so this is fine then: a = new Array(10000000); console.time(); a.splice(0, a.length); console.timeEnd(); default: 0.02001953125ms And even when setting elements on the Array.prototype: Array.prototype[10] = 123; a = new Array(10000000); console.time(); a.splice(0, a.length); console.timeEnd() VM309:1 default: 82.975830078125ms So this must have been fixed in the mean time (tested on M62). |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by cbiesin...@chromium.org
, Jun 9 2016Labels: Performance