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

perf($animate): listen for document visibility changes #14071

Merged
merged 4 commits into from
Apr 26, 2016

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Feb 17, 2016

Accessing the document for the hidden state is costly for
platforms like Electron.

Closes #14066

this.$get = ['$q', '$sniffer', '$$animateAsyncRun', '$document', '$timeout',
function($q, $sniffer, $$animateAsyncRun, $document, $timeout) {
this.$get = ['$q', '$sniffer', '$$animateAsyncRun', '$document', '$$isDocumentHidden', '$timeout',
function($q, $sniffer, $$animateAsyncRun, $document, $$isDocumentHidden, $timeout) {
Copy link
Member

Choose a reason for hiding this comment

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

$document is not needed anymore. (You can also align the arguments for consistency.)

@ArekSredzki
Copy link

@Narretz These changes should also be propagated to ngAnimate as the issue continues to exist if it is enabled.

@Narretz
Copy link
Contributor Author

Narretz commented Feb 21, 2016

@ArekSredzki the runner is the same with or without ngAnimate included, and the only other playe where hidden is checked is the queue, so this should be covered

@Narretz
Copy link
Contributor Author

Narretz commented Feb 21, 2016

It looks like the test errors are because adding the event listener populates the jqlite cache. Maybe this causes another memory leak.

@ArekSredzki
Copy link

@Narretz I had checked it before you amended your commit and the problem was still very apparent with ngAnimate included... please check now, or I will on monday :)

@Narretz
Copy link
Contributor Author

Narretz commented Feb 21, 2016

I've only changed a few cosmetic things in the ammended commit.
Like I said, these are the only two instances where document.hidden is accessed. With ngAnimate included, the whole process is slow (even without animations) for different reasons. (Mainly it needs to walk the DOM to the top to see if animations are possible / allowed). I assume this is what you are seeing. Or are you seeing he exact same functions being slow?

@ArekSredzki
Copy link

@Narretz Sorry for the sluggish response. You are correct, and I believe that this solves the issue!
When do you think it can be released?

Thanks!

Narretz added 2 commits April 26, 2016 14:13
Accessing the document for the hidden state is costly for
platforms like Electron.

Closes angular#14066
@Narretz Narretz force-pushed the fix-animate-hidden branch from 3b4cdda to 25bddfa Compare April 26, 2016 13:24
@@ -7245,22 +7245,22 @@ describe('$compile', function() {
});

inject(function($compile, $rootScope) {
expect(jqLiteCacheSize()).toEqual(0);
var cacheSize = jqLiteCacheSize();
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and a few other tests assume that the cacheSize is 0 after bootstrap. The listener for visibilitychange on the document adds a cache entry. So I thought it makes more sense to not assume a specific cacheSize on bootstrap.

Copy link
Member

Choose a reason for hiding this comment

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

OK, makes sense.

@mgol
Copy link
Member

mgol commented Apr 26, 2016

LGTM.

@Narretz
Copy link
Contributor Author

Narretz commented Apr 26, 2016

@mgol I had to change the expects for the add/removeEventListener calls to account for the fact that jquery 2.1 always calls them with the third argument set to false. Is this a functional change in jquery 2.1?

@mgol
Copy link
Member

mgol commented Apr 26, 2016

jQuery has always passed the 3rd argument (useCapture) to addEventListener because it used to be required in Firefox some time ago. jQuery 1.12 & 2.2 have stopped passing this argument as it's not been needed for a long time (IE9+ doesn't require it).

The way jQuery calls addEventListener is not its public API so we were free to change it even in a patch release. I adjusted jqLite code to do the same but only on master, v1.5.x continues to pass useCapture just in case. You'll need to adjust the expectations when cherry-picking to v1.5.x.

@Narretz
Copy link
Contributor Author

Narretz commented Apr 26, 2016

Thanks for the explanation! I've adjusted the tests to simply check the first two arguments and ignore the third.

@Narretz Narretz merged commit d71dc2f into angular:master Apr 26, 2016
Narretz added a commit to Narretz/angular.js that referenced this pull request Apr 26, 2016
perf(ngAnimate): listen for document visibility changes

Accessing the document for the hidden state is costly for
platforms like Electron. Instead, listen for visibilitychange
and store the state.

(angular#14071)
Closes angular#14066
Narretz added a commit to Narretz/angular.js that referenced this pull request Apr 26, 2016
perf(ngAnimate): listen for document visibility changes

Accessing the document for the hidden state is costly for
platforms like Electron. Instead, listen for visibilitychange
and store the state.

(angular#14071)
Closes angular#14066
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.

5 participants