This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
perf($animate): listen for document visibility changes #14071
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -7245,22 +7245,22 @@ describe('$compile', function() { | |
}); | ||
|
||
inject(function($compile, $rootScope) { | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
var cacheSize = jqLiteCacheSize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, makes sense. |
||
|
||
element = $compile('<div><div ng-repeat="x in xs" ng-if="x==1">{{x}}</div></div>')($rootScope); | ||
expect(jqLiteCacheSize()).toEqual(1); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 1); | ||
|
||
$rootScope.$apply('xs = [0,1]'); | ||
expect(jqLiteCacheSize()).toEqual(2); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 2); | ||
|
||
$rootScope.$apply('xs = [0]'); | ||
expect(jqLiteCacheSize()).toEqual(1); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 1); | ||
|
||
$rootScope.$apply('xs = []'); | ||
expect(jqLiteCacheSize()).toEqual(1); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 1); | ||
|
||
element.remove(); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 0); | ||
}); | ||
}); | ||
|
||
|
@@ -7277,22 +7277,22 @@ describe('$compile', function() { | |
}); | ||
|
||
inject(function($compile, $rootScope) { | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
var cacheSize = jqLiteCacheSize(); | ||
|
||
element = $compile('<div><div ng-repeat="x in xs" ng-if="x==1">{{x}}</div></div>')($rootScope); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize); | ||
|
||
$rootScope.$apply('xs = [0,1]'); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize); | ||
|
||
$rootScope.$apply('xs = [0]'); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize); | ||
|
||
$rootScope.$apply('xs = []'); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize); | ||
|
||
element.remove(); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize); | ||
}); | ||
}); | ||
|
||
|
@@ -7308,26 +7308,26 @@ describe('$compile', function() { | |
}); | ||
|
||
inject(function($compile, $rootScope) { | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
var cacheSize = jqLiteCacheSize(); | ||
element = $compile('<div><div ng-repeat="x in xs" ng-if="val">{{x}}</div></div>')($rootScope); | ||
|
||
$rootScope.$apply('xs = [0,1]'); | ||
// At this point we have a bunch of comment placeholders but no real transcluded elements | ||
// So the cache only contains the root element's data | ||
expect(jqLiteCacheSize()).toEqual(1); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 1); | ||
|
||
$rootScope.$apply('val = true'); | ||
// Now we have two concrete transcluded elements plus some comments so two more cache items | ||
expect(jqLiteCacheSize()).toEqual(3); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 3); | ||
|
||
$rootScope.$apply('val = false'); | ||
// Once again we only have comments so no transcluded elements and the cache is back to just | ||
// the root element | ||
expect(jqLiteCacheSize()).toEqual(1); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 1); | ||
|
||
element.remove(); | ||
// Now we've even removed the root element along with its cache | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 0); | ||
}); | ||
}); | ||
|
||
|
@@ -7364,6 +7364,7 @@ describe('$compile', function() { | |
}); | ||
|
||
inject(function($compile, $rootScope, $httpBackend, $timeout, $templateCache) { | ||
var cacheSize = jqLiteCacheSize(); | ||
$httpBackend.whenGET('red.html').respond('<p>red.html</p>'); | ||
var template = $compile( | ||
'<div ng-controller="Leak">' + | ||
|
@@ -7378,7 +7379,7 @@ describe('$compile', function() { | |
$timeout.flush(); | ||
$httpBackend.flush(); | ||
expect(linkFn).not.toHaveBeenCalled(); | ||
expect(jqLiteCacheSize()).toEqual(2); | ||
expect(jqLiteCacheSize()).toEqual(cacheSize + 2); | ||
|
||
$templateCache.removeAll(); | ||
var destroyedScope = $rootScope.$new(); | ||
|
@@ -8161,9 +8162,7 @@ describe('$compile', function() { | |
|
||
it('should not leak memory with nested transclusion', function() { | ||
inject(function($compile, $rootScope) { | ||
var size; | ||
|
||
expect(jqLiteCacheSize()).toEqual(0); | ||
var size, initialSize = jqLiteCacheSize(); | ||
|
||
element = jqLite('<div><ul><li ng-repeat="n in nums">{{n}} => <i ng-if="0 === n%2">Even</i><i ng-if="1 === n%2">Odd</i></li></ul></div>'); | ||
$compile(element)($rootScope.$new()); | ||
|
@@ -8177,7 +8176,7 @@ describe('$compile', function() { | |
expect(jqLiteCacheSize()).toEqual(size); | ||
|
||
element.remove(); | ||
expect(jqLiteCacheSize()).toEqual(0); | ||
expect(jqLiteCacheSize()).toEqual(initialSize); | ||
}); | ||
}); | ||
}); | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this in every tick (and for every runner), coudn't we listen for an event and update the function as necessary ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tick is only called when the animation completes, so only once per runner. I'm not sure how costly one function call is. Event listener is also possible. but I don't want to add another one over the one we have in $$isDocumentHidden. So maybe we could move the actual async tick into this service where it will be updated by the listener. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I confused this with the
$$rAF
's tick. Since it's indeed called one, I guess it's fine as it is.