Pankaj Parkar
Indian | 30 | Ex MVP | Angular GDE
Performance improvement might lead to rework whole feature or module
..Anonymous
Senior Software Engineer
TSS Consultancy PVT LTD
Navbar component
Search component
Input
Client-list component
Item
Item
.
.
.
Input
Client-list component
Item
Item
.
.
.
App Component
Text
Navbar Component
Search Component
Customer-list Component
Mechanism to analyse the changes and reflect them on the view "
App
Todos
Input
Button
Eat
Sleep
App
Todos
Input
Button
Eat
Diff Tree
//network Call
getDataFromServer()
.then(()=> {
//state has changed
detectChanges();
})
//timeout function
setTimeout(()=> {
//Call change detection
detectChanges();
}, 5000)
element.addEventListner('click', (event) =>{
//state could have change
detectChanges();
});
let detectChanges => () => {
if(currentState != prevState)
updateView(currentState);
}
Detect Changes Method
let originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = (data) => {
//monkey patch code
if ( URL DOES NOT POINT TO AD SERVER ) {
return originalSend.apply(this, arguments);
}
return false;
};
Zone.afterInvoke()
appliction_ref.ts
appliction_ref.ts
Source: https://github.com/angular/angular/blob/master/packages/core/src/application_ref.ts#L513-L532
There are three change detection strategy.
Change detection fires
CD -> Change Detection
@Input() name1
@Input() name2
[name]="name2"
[name]="name1"
name1 = 'Ravi'
name2 = 'Pankaj'
name1 = 'Ravi'
name2 = 'Keerti'
constructor(
private cd: ChangeDetectorRef
) {
cd.detatch();
}
some problems can be solved simple solutions like CSS & HTML or other easiest way.
Angular uses below compilation process
@angular/compiler
Angular
Code
Loaded to browser
Browser use this code
client-list component
Add customer Name
+
.
.
.
Angular has two types of Pipe.
function getNumber(val) {
return Math.random();
}
function square(val) {
return val * val;
}
Impure Function
Pure Function
In case of observable you could think of using async pipe using
Don't forget to remove unnecessary if you're not using it.
It would tend to load the default module after angular application intialize where as other way would be slightly faster
Old
Collection
Brought
new
Collection
server
https://addyosmani.com/blog/faster-javascript-memoization/
http://jamesknelson.com/5-types-react-application-state/
https://www.youtube.com/watch?v=esDKcn_1aic
https://github.com/mgechev/angular-performance-checklist
By Pankaj Parkar
Focused on How to improve Angular application performance.