This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eventListener): fix #798, improve EventTarget.addEventListener p…
…erformance (#812) * feat(performance): fix #798, improve EventTarget.addEventListener performance * add test cases * add comment to explain the implementations * add test cases for resschedule eventTask * add IE/edge and cross context check * modify document for extra flags * minor changes, define some const, move logic into __load_patch * let nodejs use new addListener/removeListener method * add nodejs test example * add eventListeners/removeAllListeners test cases for browser
- Loading branch information
1 parent
98f3903
commit b3a76d3
Showing
18 changed files
with
1,219 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
const events = require('events'); | ||
const EventEmitter = events.EventEmitter; | ||
require('../../dist/zone-node'); | ||
|
||
const emitters = []; | ||
const callbacks = []; | ||
const size = 100000; | ||
for (let i = 0; i < size; i++) { | ||
const emitter = new EventEmitter(); | ||
const callback = (function (i) { return function () { console.log(i); }; })(i); | ||
emitters[i] = emitter; | ||
callbacks[i] = callback; | ||
} | ||
|
||
function addRemoveCallback(reuse, useZone) { | ||
const start = new Date(); | ||
let callback = callbacks[0]; | ||
for (let i = 0; i < size; i++) { | ||
const emitter = emitters[i]; | ||
if (!reuse) callback = callbacks[i]; | ||
if (useZone) | ||
emitter.on('msg', callback); | ||
else | ||
emitter.__zone_symbol__addListener('msg', callback); | ||
} | ||
|
||
for (let i = 0; i < size; i++) { | ||
const emitter = emitters[i]; | ||
if (!reuse) callback = callbacks[i]; | ||
if (useZone) | ||
emitter.removeListener('msg', callback); | ||
else | ||
emitter.__zone_symbol__removeListener('msg', callback); | ||
} | ||
const end = new Date(); | ||
console.log(useZone ? 'use zone' : 'native', reuse ? 'reuse' : 'new'); | ||
console.log("Execution time: %dms", end - start); | ||
} | ||
|
||
addRemoveCallback(false, false); | ||
addRemoveCallback(false, true); | ||
addRemoveCallback(true, false); | ||
addRemoveCallback(true, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.