Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf(Scope): use remove the need for the extra watch in $watchGroup #8396

Closed
wants to merge 2 commits into from

Conversation

IgorMinar
Copy link
Contributor

Instead of using a counter and an extra watch, just schedule the reaction function via .

This gives us the same/similar ordering and coalecsing of updates as counter without the extra
overhead. Also the code is easier to read.

Since interpolation uses watchGroup, this change additionally improves performance of interpolation.

In large table benchmark digest cost went down by 15-20% for interpolation.

IgorMinar added a commit to IgorMinar/angular.js that referenced this pull request Jul 29, 2014
Instead of using a counter and an extra watch, just schedule the reaction function via .

This gives us the same/similar ordering and coalecsing of updates as counter without the extra
overhead. Also the code is easier to read.

Since interpolation uses watchGroup, this change additionally improves performance of interpolation.

In large table benchmark digest cost went down by 15-20% for interpolation.

Closes angular#8396
@IgorMinar IgorMinar added this to the 1.3.0-beta.18 milestone Jul 29, 2014
@IgorMinar
Copy link
Contributor Author

@caitp, @rodyhaddad can you please review?


return function deregisterWatchGroup() {
while (deregisterFns.length) {
deregisterFns[0]();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how this used to work. It wouldn't it result in an infinite loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to ask, because I don't see it splicing the array in the diff (but I might just be missing it).

However, is it really good to reverse the order of deregistration, assuming it's working currently? Should this be shift() instead of pop()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The removing used to happen here. It was confusing.
Since we no longer need to track which watchers are getting deregistered, this is a lot better :-)

I doubt changing pop to shift would actually change much for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just be aware that the order is changing here, and we don't really know if that will matter

Copy link
Contributor

Choose a reason for hiding this comment

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

It would change things for deregisterNotifiers in $watch, but I believe this PR should be followed by one that removes deregisterNotifiers completely.
$watchGroup was the only place they were getting used, and we don't have a reason to support them in the future.

This will make the watcherDeregister functions only splice the $$watchers array, so order wouldn't matter

Copy link
Contributor

Choose a reason for hiding this comment

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

I am all for removing deregisterNotifiers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 for removing deregisterNotifiers in a separate commit.

I realized that the order has changed, but didn't think that it could cause problems. I'll make a change to keep the original order.

@IgorMinar IgorMinar changed the title perf(Scope): use remove the need for the extra watch perf(Scope): use remove the need for the extra watch in $watchGroup Jul 29, 2014
IgorMinar added a commit to IgorMinar/angular.js that referenced this pull request Jul 29, 2014
Instead of using a counter and an extra watch, just schedule the reaction function via .

This gives us the same/similar ordering and coalecsing of updates as counter without the extra
overhead. Also the code is easier to read.

Since interpolation uses watchGroup, this change additionally improves performance of interpolation.

In large table benchmark digest cost went down by 15-20% for interpolation.

Closes angular#8396
@rodyhaddad
Copy link
Contributor

LGTM 👍

@IgorMinar
Copy link
Contributor Author

any other comments? I'll make the changes on the flight home tonight.

@caitp
Copy link
Contributor

caitp commented Jul 29, 2014

Yeah it generally looks good to me

@petebacondarwin
Copy link
Contributor

Would it be possible to add objectEquality param to watchGroup, which would be passed down to all the watches in the group? (This would be in a separate commit/PR obviously)

Instead of using a counter and an extra watch, just schedule the reaction function via .

This gives us the same/similar ordering and coalecsing of updates as counter without the extra
overhead. Also the code is easier to read.

Since interpolation uses watchGroup, this change additionally improves performance of interpolation.

In large table benchmark digest cost went down by 15-20% for interpolation.

Closes angular#8396
We no longer have a need for this feature that was added to primarily support
$watchGroup (see previous commit).

BREAKING CHANGE: deregisterNotifier callback for $watch is no longer available

This api was available only in the last few 1.3 beta versions and is not
very useful for applications, so we don't expect that anyone will be affected
by this change.
@IgorMinar
Copy link
Contributor Author

I changed the deregistration fn order and added a commit to remove the deregister notifier so we should be all set.

@petebacondarwin we don't want to encourage people to use slow deep watching.

@IgorMinar IgorMinar closed this in 28540c8 Jul 31, 2014
@caitp caitp reopened this Aug 8, 2014
@caitp
Copy link
Contributor

caitp commented Aug 8, 2014

This caused some problems, reproduced in http://plnkr.co/edit/6vAF3sBLbGsYWTGTS6bv?p=preview (basically with this SHA their $watch listener is never invoked) #8542

@caitp caitp modified the milestones: 1.3.0-beta.18, 1.3.0-beta.19 Aug 8, 2014
@rodyhaddad
Copy link
Contributor

It never got invoked because the parseFns of $interpolate would be an empty array. Without this optimization, the changeCount watcher would trigger once, hence trigger the listener once.

I'm trying to think of a good way to handle the situation when the array is empty. This optimization is worth an extra if imo

@caitp
Copy link
Contributor

caitp commented Aug 8, 2014

I agree --- but I think it might have to wait for next week :(

@caitp
Copy link
Contributor

caitp commented Aug 8, 2014

assuming we are shipping today --- I'm not sure if we're retesting g3 or what

rodyhaddad pushed a commit to rodyhaddad/angular.js that referenced this pull request Aug 14, 2014
Instead of using a counter and an extra watch, just schedule the reaction function via .

This gives us the same/similar ordering and coalecsing of updates as counter without the extra
overhead. Also the code is easier to read.

Since interpolation uses watchGroup, this change additionally improves performance of interpolation.

In large table benchmark digest cost went down by 15-20% for interpolation.

Closes angular#8396
@IgorMinar IgorMinar closed this in 3f0e642 Aug 15, 2014
@rodyhaddad
Copy link
Contributor

Landed again with a fix as 1a05daf...bf0e837

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants