Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two hot path optimizations #3513

Merged
merged 2 commits into from
Jun 9, 2016
Merged

Two hot path optimizations #3513

merged 2 commits into from
Jun 9, 2016

Conversation

jridgewell
Copy link
Contributor

  • Observable
    • Array#forEach is slow. Use for loops for hot code.
  • Pass
    • No need to allocate a function every time. Create a bound #pass, use it.

Also a little style cleanup. I'll revert those if you want.

@@ -64,9 +62,11 @@ export class Observable {
* @param {TYPE} event
*/
fire(event) {
this.handlers_.forEach(handler => {
const handlers = this.handlers_;
for (let i = 0; i< handlers.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@erwinmombay
Copy link
Member

@jridgewell good stuff 💯 . LGTM

@cramforce
Copy link
Member

Love it.

LGTM

@jridgewell jridgewell merged commit 9e632d8 into ampproject:master Jun 9, 2016
@jridgewell jridgewell deleted the opts branch June 9, 2016 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants