+ All Categories
Home > Technology > Angular Extreme Performance

Angular Extreme Performance

Date post: 21-Jan-2018
Category:
Upload: gustavo-costa
View: 690 times
Download: 2 times
Share this document with a friend
65
Extreme Performance
Transcript
Page 1: Angular  Extreme Performance

Extreme Performance

Page 2: Angular  Extreme Performance

Gustavo Costa

Page 3: Angular  Extreme Performance

@willgmbr

Page 4: Angular  Extreme Performance

N R

Pilares da Performance Front-end

Network performance Runtime performance

Page 5: Angular  Extreme Performance

Bundling1

2 Minification…+

3 Tree-shaking

4 AOT

5 Lazy-load

6 Service Worker

Network performance

Page 6: Angular  Extreme Performance

W

Webpack

Tools

B

Browserify

R

Rollup

R

SystemJS

G

Gulp

G

Grunt

G

GCC

?

Page 7: Angular  Extreme Performance

#1 Bundling

Page 8: Angular  Extreme Performance

#1 Bundling

Page 9: Angular  Extreme Performance

#2 Minification…+

Dead code

Ofuscation

Minification

UglifyJS

Page 10: Angular  Extreme Performance

#3 Tree Shaking

Page 11: Angular  Extreme Performance

JIT AoT

#4 AoT

JIT (Just in time)Compilation

AoT(Ahead of time)

Compilation

Page 12: Angular  Extreme Performance

• Compilamos para gerar um código mais eficiente para as VMs

Compilar?

• Versão 2 > cada componente tem seu PRÓPRIO Change detector.

• O Angular precisa ‘compilar' todo o template para também conseguir aplicar o tree shaking

Page 13: Angular  Extreme Performance

1 2

componente.js(transpilado do typescript)

Entendendo um Componente Angular

componente-internal.js(ngfactory)

my-component

Page 14: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component.ts my-component.js

Page 15: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

• Baixa todos os Javascripts.

• Angular é iniciado, verifica se é para iniciar em JIT ou AoT.

• Angular precisa compilar TODOS os componentes em JIT

• A aplicação é iniciada.

Page 16: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component.js

• Angular precisa ‘compilar’ esse template e criar tudo isso via javascript, nosso internal component ou (ngfactory)

• Com isso criar o Change detector desse componente.

Page 17: Angular  Extreme Performance

ng serve

Page 18: Angular  Extreme Performance

• TODO o código do Angular foi IMPORTADO e TODO SEU COMPILER e suas dependências também.

KEEP CALM!

• Não há ABSOLUTAMENTE NENHUMA técnica de performance nesse código (minificação, tree shaking etc…)

• Isso é que faz deixar o ‘auto reload’ rápido desenvolvendo uma aplicação Angular

Page 19: Angular  Extreme Performance

AoT

AoT(Ahead of time)

Compilation

ng serve —aot

ng build—aot

Page 20: Angular  Extreme Performance

AoT

AoT(Ahead of time)

Compilation

• Também tem muito benefício em runtime performance, veremos mais na frente.

Page 21: Angular  Extreme Performance

JIT AoT

Recap #4 AoT

JIT (Just in time)Compilation

AoT(Ahead of time)

Compilation

Page 22: Angular  Extreme Performance

Vue

Page 23: Angular  Extreme Performance

#5 lazy-loadPeople Component01 Person

Component02

Page 24: Angular  Extreme Performance

PeopleModule

PeopleService

PeopleComponent

PersonModule

PersonService

PersonComponent

AppComponent

AppRouting

AppModule

/

/person/:id

lazylazy

eager

#5 lazy-load

Page 25: Angular  Extreme Performance
Page 26: Angular  Extreme Performance

Lazy demo

Page 27: Angular  Extreme Performance
Page 28: Angular  Extreme Performance
Page 29: Angular  Extreme Performance
Page 30: Angular  Extreme Performance

HTTP21

2 ServiceWorker

3 Application Shell

4 CacheAPI

5 Pre-fetching

Outras técnicas

Page 31: Angular  Extreme Performance

easy

Page 32: Angular  Extreme Performance

Angular CLI

Page 33: Angular  Extreme Performance

Build time!

ng build --prod

Page 34: Angular  Extreme Performance

#5 compression

Page 35: Angular  Extreme Performance
Page 36: Angular  Extreme Performance

GCC + BROTLI

Page 37: Angular  Extreme Performance
Page 38: Angular  Extreme Performance

Em breve teremos hello world do Angular com apenas:

40kb!

Page 39: Angular  Extreme Performance

AoT1

3 Change Detection

4 trackby

5 WebWorkers

Runtime performance

enableProdMode2

6 Server-side rendering

Page 40: Angular  Extreme Performance

JIT AoT

#1 AoT

JIT (Just in time)Compilation

AoT(Ahead of time)

Compilation

Page 41: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

• Baixa todos os Javascripts.

• Angular é iniciado, verifica se é para iniciar em JIT ou AoT.

• Angular precisa compilar TODOS os componentes em JIT

• A aplicação é iniciada.

Page 42: Angular  Extreme Performance

AoT

AoT(Ahead of time)

Compilation

• Baixa todos os Javascripts.

• Angular é iniciado, inicia com AoT

• Angular precisa compilar TODOS os componentes em JIT

• A aplicação é iniciada.

Page 43: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component.ts my-component.js

Page 44: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component.js

my-component-internal.js

Page 45: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component-internal.js

create()

Page 46: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component.tscreate()

Page 47: Angular  Extreme Performance

JIT

JIT (Just in time)Compilation

my-component-internal.js

detectChanges()

Page 48: Angular  Extreme Performance

AoT

AoT(Ahead of time)

Compilation

Page 49: Angular  Extreme Performance

3x - 10x

Page 50: Angular  Extreme Performance

#2 enableProdMode

Page 51: Angular  Extreme Performance

SMARTER?

#3 Change Detection

Page 52: Angular  Extreme Performance

ChangeDetection.Default

user === valorAntigoDoUser ?

user.name === valorAntigoDoUser.name ?user.bio === valorAntigoDoUser.bio ?

user.propsInView * n

MUTABILIDADE

Page 53: Angular  Extreme Performance

ChangeDetection.OnPush

user === valorAntigoDoUser ?

run change detection! :-)

IMUTABILIDADE

Page 54: Angular  Extreme Performance

ChangeDetection Demo

Page 55: Angular  Extreme Performance

Notifique o Angular!

Page 56: Angular  Extreme Performance

markForCheck();

Page 57: Angular  Extreme Performance
Page 58: Angular  Extreme Performance

#4 trackby

Page 59: Angular  Extreme Performance

#5 WebWorkers

Event Loop

Single thread

Page 60: Angular  Extreme Performance

#6 Server-side rendering

Page 61: Angular  Extreme Performance
Page 62: Angular  Extreme Performance

AoT !== SSR

Otimiza JS Gera HTML/CSS

Page 63: Angular  Extreme Performance

• Angular universal

Ferramentas

• Vue.js Server-Side

• import ReactDOMServer from 'react-dom/server';

Page 64: Angular  Extreme Performance

https://github.com/mgechev/angular-performance-checklist

https://blog.thoughtram.io

https://victorsavkin.com

https://twitter.com/jeffbcross

Referências

https://angular.io

Page 65: Angular  Extreme Performance

Recommended