Shower Presentation Engine

Yours Truly, Famous Inc.

Angular Ivy Overview

Angular logo

Agenda

  1. What is a rendering engine in JS frameworks?
  2. Why Ivy?
  3. How does it works?
  4. Features

What is a rendering engine?

Part of a framework that translates your templates into DOM elements

React DOM library npm screenshot

Why Ivy?

Angular issues

  1. Big bundle size
  2. Compilation
  3. Lazy loading
  4. Debugging

Component

                <div>
                    <span>{{title}}</span>
                    <child-cmp *ngIf="show"></child-cmp>
                </div>
            

View Engine rendering pipeline

Angular 4-6 pipeline

View Engine output

ng factories

Compiled with View Engine

view engine code

View Engine

                    // Angular core code
                    function createViewNodes(view: ViewDef) {
                        view.nodes.foreach(node => {
                            if(isElementDef(node)) createElement(node);
                            if(hasListeners(node)) listenToElementOutput(node);
                            if(hasPipe(node)) createPipeInstance(node);
                        });
                    }
            

Ivy rendering pipeline

Angular ivy pipeline

Compiled with Ivy

ivy output

Compiled with Ivy

ivy output

Compiled with Ivy

ivy output

Ivy uses a new instruction set

Runtime is based on incremental DOM

incremental dom github

Why incremental DOM?

Compiled with Ivy

ivy output

Locality

Non-Locality in View Engine

view engine locality

Locality in Ivy

ivy locality

Locality in Ivy

ivy locality

Locality in Ivy

Now framework is tree-shakable!

Tree-shaking in Ivy

tree shaking in ivy

Ivy can tree-shake

ComponentFactoryResolver

Essentially a Map<Component, ComponentFactory>

In Ivy, every component is its own factory

~5kB "Hello World" application

(minified, compressed)

Create application with Ivy enabled

                ng new my-app --experemental-ivy
            

Compile your app with Ivy

                node_modules/.bin/ivy-ngcc
            

Convert node modules to Ivy-compatible format

Compile your app with Ivy

Add to tsconfig.json

                "angularCompilerOptions": {
                  "enableIvy": "ngtsc"
                }
            

main.ts

                import { ɵrenderComponent as renderComponent } from '@angular/core';
                import { AppComponent } from './app/app.component';
                
                renderComponent(AppComponent);
            

Compile your app with Ivy

sad smile

What about real-world application?

Angular Ivy performance

Other features

Ugly error stack traces

ng error trace

Debugging

                $0
                const cmp = ng.getComponent($0)
            

Ivy lazy-loading

lazy loading

Guards

lguards

What's next?

Deep dive

Other resources

Thanks!

Angular logo