Skip to content

Commit

Permalink
perf: gather all event listeners in parallel (#1667)
Browse files Browse the repository at this point in the history
* issue devtools commands to get event listeners in parallel

* disable websocket compression for cri
  • Loading branch information
brendankenny committed Feb 8, 2017
1 parent fc858ea commit c6aeb33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lighthouse-core/gather/connections/cri.js
Expand Up @@ -46,7 +46,9 @@ class CriConnection extends Connection {
this._pageId = response.id;

return new Promise((resolve, reject) => {
const ws = new WebSocket(url);
const ws = new WebSocket(url, {
perMessageDeflate: false
});
ws.on('open', () => {
this._ws = ws;
resolve();
Expand Down
Expand Up @@ -112,13 +112,10 @@ class EventListeners extends Gatherer {
* listeners found across the elements.
*/
collectListeners(nodes) {
return nodes.reduce((chain, node) => {
return chain.then(prevArr => {
// Call getEventListeners once for each node in the list.
return this.getEventListeners(node.element ? node.element.nodeId : node)
.then(result => prevArr.concat(result));
});
}, Promise.resolve([]));
// Gather event listeners from each node in parallel.
return Promise.all(nodes.map(node => {
return this.getEventListeners(node.element ? node.element.nodeId : node);
})).then(nestedListeners => [].concat(...nestedListeners));
}

beforePass(options) {
Expand Down

0 comments on commit c6aeb33

Please sign in to comment.