Slide 1

Slide 1 text

Measuring Performance of AngularJS apps San Francisco, December 2015 Kenneth @auchenberg

Slide 2

Slide 2 text

Soo, performance?

Slide 3

Slide 3 text

Page load

Slide 4

Slide 4 text

Steve Souders

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

YSlow

Slide 7

Slide 7 text

PageSpeed

Slide 8

Slide 8 text

We build API’s to help us

Slide 9

Slide 9 text

Navigation Timing API https://blogs.windows.com/buildingapps/2011/08/02/measuring-mobile-site-performance-using-the-w3c-navigation-timing-api/

Slide 10

Slide 10 text

Resource Timing API http://www.stevesouders.com/blog/2014/11/25/serious-confusion-with-resource-timing/

Slide 11

Slide 11 text

Server Initial payload Browser Server-side web apps

Slide 12

Slide 12 text

The web has changed

Slide 13

Slide 13 text

Application runtime

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Server/CDN Initial payload Browser Client-side web apps API App Page load App boot

Slide 16

Slide 16 text

Client-side frameworks

Slide 17

Slide 17 text

Application performance Browser

Slide 18

Slide 18 text

Application performance

Slide 19

Slide 19 text

Chrome DevTools: Timeline

Slide 20

Slide 20 text

Chrome DevTools: CPU Profiler

Slide 21

Slide 21 text

Where is “my app” timeline?

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

for AngularJS

Slide 24

Slide 24 text

Framework specific

Slide 25

Slide 25 text

Trace levels App framework Browser primitives App Template Caching Storage HTTP XHR/WebSocket MutationObservers LocalStorage Reflow Paint Rasterize Compose viewport engine

Slide 26

Slide 26 text

Error logging + Performance

Slide 27

Slide 27 text

Installation

Slide 28

Slide 28 text

Error logging window.onError + “magic”

Slide 29

Slide 29 text

Error logging 1. Error parsing 2. Stack frame generation 3. Stack frame normalization

Slide 30

Slide 30 text

Code instrumentation Performance

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Challenges

Slide 33

Slide 33 text

What is “app load”? (Pageload)

Slide 34

Slide 34 text

What is “app ready”? (DOMcontentReady)

Slide 35

Slide 35 text

What is “view changed”? (onhashchange)

Slide 36

Slide 36 text

AngularJS Page cyclus Bootstrap Router $routeChangeStart $stateChangeSuccess Controller Services $viewContentLoaded Directives View UI Router ng-route (ngView)

Slide 37

Slide 37 text

What to instrument? AngularJS $resource $http $templateRequest $httpBackend $compile $module $service $controller $cacheFactory $templateCache $directives ngBind, ngClass, ngMode, ngIf, ngInclude, ngRepeat, ngSrc, ngStyle, ngSwitch, ngTransclude

Slide 38

Slide 38 text

$decorate to instrument

Slide 39

Slide 39 text

Bootstrap module.config $decorate $rootScope $viewContentLoaded Router Route controller $stateChangeSuccess $routeChangeStart Start transaction Instrument TraceBuffer ngOpbeat TransactionStore ngView $viewContentLoaded End transaction $routeChangeStart opbeatFunctionWrapper new Trace() Transport scheduler Processing Instrumentation flow

Slide 40

Slide 40 text

Slide 41

Slide 41 text

Our breakdown

Slide 42

Slide 42 text

Behind the scenes

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

AngularJS $injection system …

Slide 45

Slide 45 text

$injection toString() madness

Slide 46

Slide 46 text

Replicate function arguments

Slide 47

Slide 47 text

Resolve loaded modules

Slide 48

Slide 48 text

V8 + Arguments

Slide 49

Slide 49 text

V8 + Arguments optimized Source: https://github.com/GoogleChrome/devtools-docs/issues/53#issuecomment-51941358 Explanation: http://stackoverflow.com/questions/29198195/whats-the-deal-with-optimising-arguments

Slide 50

Slide 50 text

Error stack frame normalization Firefox Chrome

Slide 51

Slide 51 text

SpiderMonkey naming convention Source: https://developer.mozilla.org/en-US/docs/Tools/Debugger-API/Debugger.Object#Accessor_Properties_of_the_Debugger.Object_prototype

Slide 52

Slide 52 text

Error stack frame normalization Normalized

Slide 53

Slide 53 text

opbeat.com/angularjs

Slide 54

Slide 54 text

github.com/opbeat/opbeat-js Open Source

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Thanks