Gleb Bahmutov PRO
JavaScript ninja, image processing expert, software quality fanatic
KENSHO
Kensho Angular
Kensho Angular
Kensho Angular
Kensho Angular
"Finding 1000 primes takes a long time ..."
- client
Kensho Angular
Your application should have "ports" for performance diagnostics
Kensho Angular
car adapter
i.e. Async methods should return / store a promise on the scope
Kensho Angular
console.profile('action');
$q.when(scope.foo())
.finally(function () {
console.profileEnd('action');
});
Kensho Angular
Extra code for message-passing actions
$scope.cellClicked = function() {
// Simulate an AJAX request:
$timeout(function() {
$scope.status.searchResults = ...;
}, randomMillis());
}
$scope.cellClicked = function() {
// Simulate an AJAX request:
$timeout(function() {
$scope.status.searchResults = ...;
}, randomMillis(), false);
}
Table update runs in 0.5 seconds
$http.useApplyAsync(true);
<tr ng-repeat="hour in hours">
<td ng-repeat="day in days">
<my-calendar-cell hour="{{hour}}"
day="{{day}}"></my-calendar-cell>
</td>
</tr>
- me
<tr ng-repeat="hour in ::hours track by $index">
<td ng-repeat="day in ::days track by $index">
<my-calendar-cell hour="{{::hour}}"
day="{{::day}}"></my-calendar-cell>
</td>
</tr>
Hmm, are we updating DOM on each table cell creation?
<tr boom-repeat="hour in hours">
<td boom-repeat="day in days">
<my-calendar-cell hour="{{hour}}"
day="{{day}}"></my-calendar-cell>
</td>
</tr>
Do not attach the list to the DOM until all items are ready
(benv + jsdom + browserify - Node parts)
N web workers
Load
Angular 1.x app
Look at the big picture, not hacks
<ul class="list">
<li class="person">
<div class="first">John</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
<li class="person">
<div class="first">Mary</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
</ul>
designer
<ul class="list">
<li class="person">
<div class="first">John</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
<li class="person">
<div class="first">Mary</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="..." ng-repeat="person in people">
<div ng-class="...">{{ person.first | ... }}</div>
<div ng-class="last">{{ person.last | ... }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
designer or developer
<ul class="list">
<li class="person">
<div class="first">John</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
<li class="person">
<div class="first">Mary</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="..." ng-repeat="person in people">
<div ng-class="...">{{ person.first | ... }}</div>
<div ng-class="last">{{ person.last | ... }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="computed" ng-repeat="person in people track by person.id">
<div ng-class="first-computed">{{:: person.first-computed }}</div>
<div ng-class="last-computed">{{:: person.last-computed }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
developer
<ul class="list">
<li class="person">
<div class="first">John</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
<li class="person">
<div class="first">Mary</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="..." ng-repeat="person in people">
<div ng-class="...">{{ person.first | ... }}</div>
<div ng-class="last">{{ person.last | ... }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="computed" ng-repeat="person in people track by person.id">
<div ng-class="first-computed">{{:: person.first-computed }}</div>
<div ng-class="last-computed">{{:: person.last-computed }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
good developer
// no need to run global digest
$timeout(..., ms, false);
// combine digests after HTTP
$http.useApplyAsync(true);
<ul class="list">
<li class="person">
<div class="first">John</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
<li class="person">
<div class="first">Mary</div>
<div class="last">Smith</div>
<img class="avatar" src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="..." ng-repeat="person in people">
<div ng-class="...">{{ person.first | ... }}</div>
<div ng-class="last">{{ person.last | ... }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
<ul class="list">
<li ng-class="computed" ng-repeat="person in people track by person.id">
<div ng-class="first-computed">{{:: person.first-computed }}</div>
<div ng-class="last-computed">{{:: person.last-computed }}</div>
<img ng-class="..." ng-src="..." />
</li>
</ul>
// no need to run global digest
$timeout(..., ms, false);
// combine digests after HTTP
$http.useApplyAsync(true);
Designer!
Developer
UI / UX
Performance
var HelloMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
ReactDOM.render(<HelloMessage name="John" />, mountNode);
Developer
UI / UX / Performance
2
Kensho Angular
Kensho Angular
By Gleb Bahmutov
Once your Angular application has the features you need, the next step is usually focused on improving its performance, such as the initial load time and responsiveness to user’s commands. The application has to execute quickly in order to be useful. Is the Angular framework fast or slow? I argue that it is very fast, but requires you to know how to measure and optimize the right bottlenecks.
JavaScript ninja, image processing expert, software quality fanatic