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
chore(benchpress): add ngRepeat animation benchmark #13976
Closed
Closed
Changes from all commits
Commits
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 hidden or 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,9 @@ | ||
'use strict'; | ||
|
||
angular.module('repeatAnimateBenchmark', ['ngAnimate']) | ||
.config(function($animateProvider) { | ||
$animateProvider.classNameFilter(/animate-/); | ||
}) | ||
.run(function($rootScope) { | ||
$rootScope.fileType = 'classfilter'; | ||
}); |
This file contains hidden or 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,6 @@ | ||
'use strict'; | ||
|
||
angular.module('repeatAnimateBenchmark', []) | ||
.run(function($rootScope) { | ||
$rootScope.fileType = 'noanimate'; | ||
}); |
This file contains hidden or 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,7 @@ | ||
'use strict'; | ||
|
||
angular.module('repeatAnimateBenchmark', ['ngAnimate']) | ||
.run(function($rootScope) { | ||
$rootScope.fileType = 'default'; | ||
}); | ||
|
This file contains hidden or 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,20 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
scripts: [ | ||
{ | ||
id: 'angular', | ||
src: '/build/angular.js' | ||
}, | ||
{ | ||
id: 'angular-animate', | ||
src: '/build/angular-animate.js' | ||
}, | ||
{ | ||
id: 'app', | ||
src: 'app.js', | ||
}, | ||
{ | ||
src: 'common.js' | ||
}] | ||
}); | ||
}; |
This file contains hidden or 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,122 @@ | ||
'use strict'; | ||
|
||
(function() { | ||
var app = angular.module('repeatAnimateBenchmark'); | ||
|
||
var animateProvider; | ||
|
||
app.config(function($compileProvider, $animateProvider) { | ||
if ($compileProvider.debugInfoEnabled) { | ||
$compileProvider.debugInfoEnabled(false); | ||
} | ||
|
||
}); | ||
|
||
app.run(function($animate) { | ||
if ($animate.enabled) { | ||
$animate.enabled(true); | ||
} | ||
}); | ||
|
||
app.controller('DataController', function($scope, $rootScope, $animate) { | ||
var totalRows = 500; | ||
var totalColumns = 20; | ||
|
||
var data = $scope.data = []; | ||
|
||
function fillData() { | ||
if ($animate.enabled) { | ||
$animate.enabled($scope.benchmarkType === 'globallyDisabled' ? false : true); | ||
} | ||
|
||
for (var i=0; i<totalRows; i++) { | ||
data[i] = []; | ||
for (var j=0; j<totalColumns; j++) { | ||
data[i][j] = { | ||
i: i | ||
}; | ||
} | ||
} | ||
} | ||
|
||
benchmarkSteps.push({ | ||
name: 'enter', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
fillData(); | ||
}); | ||
} | ||
}); | ||
|
||
benchmarkSteps.push({ | ||
name: 'leave', | ||
fn: function() { | ||
$scope.$apply(function() { | ||
data = $scope.data = []; | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
app.directive('disableAnimations', function($animate) { | ||
return { | ||
link: { | ||
pre: function(s, e) { | ||
$animate.enabled(e, false); | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
app.directive('noop', function($animate) { | ||
return { | ||
link: { | ||
pre: angular.noop | ||
} | ||
}; | ||
}); | ||
|
||
app.directive('baseline', function($document) { | ||
return { | ||
restrict: 'E', | ||
link: function ($scope, $element) { | ||
var document = $document[0]; | ||
|
||
var i, j, row, cell, comment; | ||
var template = document.createElement('span'); | ||
template.setAttribute('ng-repeat', 'foo in foos'); | ||
template.classList.add('ng-scope'); | ||
template.appendChild(document.createElement('span')); | ||
template.appendChild(document.createTextNode(':')); | ||
|
||
function createList() { | ||
for (i = 0; i < $scope.data.length; i++) { | ||
row = document.createElement('div'); | ||
$element[0].appendChild(row); | ||
for (j = 0; j < $scope.data[i].length; j++) { | ||
cell = template.cloneNode(true); | ||
row.appendChild(cell); | ||
cell.childNodes[0].textContent = i; | ||
cell.ng3992 = 'xxx'; | ||
comment = document.createComment('ngRepeat end: bar in foo'); | ||
row.appendChild(comment); | ||
} | ||
|
||
comment = document.createComment('ngRepeat end: foo in foos'); | ||
$element[0].appendChild(comment); | ||
} | ||
} | ||
|
||
$scope.$watch('data.length', function(newVal) { | ||
if (newVal === 0) { | ||
while ($element[0].firstChild) { | ||
$element[0].removeChild($element[0].firstChild); | ||
} | ||
} else { | ||
createList(); | ||
} | ||
}); | ||
} | ||
}; | ||
}); | ||
})(); |
This file contains hidden or 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,70 @@ | ||
<div ng-app="repeatAnimateBenchmark" ng-cloak> | ||
<div ng-controller="DataController"> | ||
<div class="container-fluid"> | ||
<p> | ||
Tests rendering of an ngRepeat with 1000 elements.<br> | ||
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. 1000 --> 500 or 10000 (?) 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. 500 actually :) |
||
Animations can be enabled / disabled in different ways.<br> | ||
Two tests require reloading the app with different module / app configurations. | ||
</p> | ||
|
||
<div><label><input type="radio" ng-model="benchmarkType" value="none">none: </label></div> | ||
<div><label><input type="radio" ng-model="benchmarkType" value="baseline">baseline (vanilla Javascript): </label></div> | ||
<div><label><input type="radio" ng-model="benchmarkType" ng-disabled="fileType !== 'default'" value="enabled">enabled : </label> (requires <a href="./">app.js</a>)</div> | ||
<div><label><input type="radio" ng-model="benchmarkType" ng-disabled="fileType !== 'default' && fileType !== 'classfilter'" value="globallyDisabled">globally disabled:</label> (requires <a href="./">app.js</a> or <a href="?app=app-classfilter.js">app-classfilter.js</a>)</div> | ||
<div><label><input type="radio" ng-model="benchmarkType" ng-disabled="fileType !== 'default'" value="disabledParentElement">disabled by $animate.enabled() on parent element: </label> (requires <a href="./">app.js</a>)</div> | ||
<div><label><input type="radio" ng-model="benchmarkType" ng-disabled="fileType !== 'noanimate'" value="noanimate">Without ngAnimate:</label> (requires <a href="?app=app-noanimate.js">app-noanimate.js</a>)</div> | ||
<div><label><input type="radio" ng-model="benchmarkType" ng-disabled="fileType !== 'classfilter'" value="disabledClassFilter">disabled by classNameFilter on element:</label> (requires <a href="?app=app-classfilter.js">app-classfilter.js</a>)</div> | ||
|
||
<ng-switch on="benchmarkType"> | ||
<baseline ng-switch-when="baseline"> | ||
</baseline> | ||
<div ng-switch-when="noanimate"> | ||
<div noop> | ||
<div ng-repeat="row in data"> | ||
<span ng-repeat="column in row"> | ||
<span>{{column.i}}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-switch-when="enabled"> | ||
<div noop> | ||
<div ng-repeat="row in data"> | ||
<span ng-repeat="column in row"> | ||
<span>{{column.i}}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-switch-when="globallyDisabled"> | ||
<div noop> | ||
<div ng-repeat="row in data"> | ||
<span ng-repeat="column in row"> | ||
<span>{{column.i}}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-switch-when="disabledClassFilter"> | ||
<div noop> | ||
<div ng-repeat="row in data"> | ||
<span class="disable-animations" ng-repeat="column in row"> | ||
<span>{{column.i}}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-switch-when="disabledParentElement"> | ||
<div disable-animations> | ||
<div ng-repeat="row in data"> | ||
<span ng-repeat="column in row"> | ||
<span>{{column.i}}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-switch> | ||
|
||
</div> | ||
</div> | ||
</div> |
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.
I thought the magic number was
339
...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.
👍