RESOLVED WONTFIX 96371
Web Inspector: Avoid slice-ing listeners array in WI.Object.prototype.dispatchEventToListeners
https://bugs.webkit.org/show_bug.cgi?id=96371
Summary Web Inspector: Avoid slice-ing listeners array in WI.Object.prototype.dispatc...
Alexander Pavlov (apavlov)
Reported 2012-09-11 03:44:12 PDT
Rationale: According to http://jsperf.com/slice-vs-loop-copy, loop-copying an array of 3 elements vs slice(0) is about 2.8 times faster on V8 and almost 2 times faster on JSC. The difference increases with the array length decrease. This is critical for event dispatching-intensive code paths (e.g. continuous DOM updates). Test: While profiling Web Inspector running against a page with lots of dynamically modified attributes, the patched version turned out to be about 30% faster than the original one (3.8 sec vs. 5.1 sec).
Attachments
Patch (2.22 KB, patch)
2012-09-11 03:51 PDT, Alexander Pavlov (apavlov)
vsevik: review-
Alexander Pavlov (apavlov)
Comment 1 2012-09-11 03:51:20 PDT
Vsevolod Vlasov
Comment 2 2012-09-11 09:07:29 PDT
Comment on attachment 163325 [details] Patch This will probably regress scenarios when we have more listeners.
Yury Semikhatsky
Comment 3 2012-09-11 22:14:31 PDT
(In reply to comment #2) > (From update of attachment 163325 [details]) > This will probably regress scenarios when we have more listeners. We may add a check for a threshold if this optimization has a noticeable effect.
Pavel Feldman
Comment 4 2012-09-11 23:42:28 PDT
If you think performance is critical here - do copy-on-write. I.e. iterate over original and put it into the iterating-over Set. If upon addEventListener your list is in Set - clone it. Finally we put has() method into our Map and make Set implementation possible.
Vsevolod Vlasov
Comment 5 2012-09-12 00:24:53 PDT
(In reply to comment #4) > If you think performance is critical here - do copy-on-write. I.e. iterate over original and put it into the iterating-over Set. If upon addEventListener your list is in Set - clone it. Finally we put has() method into our Map and make Set implementation possible. This was actually all about one element listeners array case. Apparently putting something into the set makes things even slower in this case. Special-casing one element case might help but I don't think that we currently have a scenario where this whole issue is a problem.
Brian Burg
Comment 6 2014-12-13 15:41:29 PST
the linked jsperf shows manual copy about 75% faster than for-loop. Why can't we optimize Array.prototype.slice() instead? I'm not convinced this is a big perf issue right now, since jsperf is probably not representative of how WI code will be optimized.
Radar WebKit Bug Importer
Comment 7 2014-12-17 11:23:31 PST
Timothy Hatcher
Comment 8 2016-02-04 19:50:09 PST
We replaced this code recently.
Note You need to log in before you can comment on or make changes to this bug.