This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slides.html
428 lines (366 loc) · 13.9 KB
/
slides.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular Compile Cycle</title>
<meta name="description" content="Angular CLI and Tooling in Angular 2">
<meta name="author" content="Alex Miller">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/moon.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<script src="https://use.fontawesome.com/38769a7187.js"></script>
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Understanding the Angular Compile Cycle</h1>
<h3>Compiling JavaScript for fun and profit</h3>
<p>
<small>Alex Miller <a href="http://twitter.com/amahopa">@amahopa</a></small>
</p>
</section>
<section>
<h2>Agenda</h2>
<ul>
<li>Compilers & Lies</li>
<li>Angular Compilation</li>
<li>Fun & Profit</li>
</ul>
</section>
<!--Why Compile-->
<section>
<h2>What does a compiler do?</h2>
<h3 class="fragment">It compiles.</h3>
</section>
<section>
<h2>What is compilation?</h2>
<h3 class="fragment">¯\_(ツ)_/¯</h3>
<h3 class="fragment">lets figure it out</h3>
<h4 class="fragment">( <i class="fa fa-magic" alt="compilation"></i> means compilation )</h3>
</section>
<section>
<h3>Def 1: Code =>
<i class="fa fa-magic" alt="compilation"></i> => Running Application<sup>*</sup></h3>
<p class="fragment"><sup>*</sup>This is a lie</p>
<aside class="notes">
<!--Compiler turns code into a running application-->
<!--This is roughly the definition used by Tobias Bosch -->
</aside>
</section>
<section>
<h2>C++</h2>
<h3>C++ => <i class="fa fa-magic" alt="compilation"></i> =>
Native Code => Asked to Run => Running Application</h3>
<h4 class="fragment">Ahead of time compilation</h3>
<aside classs="notes">
<!--Compiler turns code into code that can be run as an application-->
<!--Pre-compilation-->
</aside>
</section>
<section data-transition="none-out">
<h3>Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3 style="visibility: hidden">Def 2: Code => <i class="fa fa-magic" alt="compilation"></i> => Runnable Code<sup style="visibility: hidden">*</sup></h3>
<p style="visibility: hidden"><sup>*</sup>text</p>
<!--<p class="fragment"><sup>*</sup>This is still a lie</p>-->
<!--Compiler turns code into a running application-->
</section>
<section data-transition="none">
<h3 style="text-decoration: line-through">Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3>Def 2: Code =>
<i class="fa fa-magic" alt="compilation"></i>
=> Runnable Code<sup style="visibility: hidden">*</sup></h3>
<p style="visibility: hidden"><sup>*</sup>text</p>
<!--<p class="fragment"><sup>*</sup>This is still a lie</p>-->
<!--Compiler turns code into a running application-->
</section>
<section data-transition="none-in">
<h3 style="text-decoration: line-through">Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3>Def 2: Code => <i class="fa fa-magic" alt="compilation"></i> => Runnable Code<sup>*</sup></h3>
<p><sup>*</sup>This is still a lie</p>
<!--Compiler turns code into a running application-->
</section>
<section>
<h2>C#/Java</h2>
<h3>C#/Java => <i class="fa fa-magic" alt="compilation"></i> =>
Byte Code => Asked to Run => <i class="fa fa-magic" alt="compilation"></i> => Native Code => Running Application</h3>
<h4 class="fragment">Ahead of time compilation & Just in Time Compilation</h3>
<aside classs="notes">
<!--Compiler turns code into code that can be run as an application-->
<!--Pre-compilation-->
</aside>
</section>
<section data-transition="none">
<h3 style="text-decoration: line-through">Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3>Def 2: Code => <i class="fa fa-magic" alt="compilation"></i> => Runnable Code</h3>
<h3 style="visibility: hidden">Def 3: </h3>
<p style="visibility: hidden"><sup>*</sup>This is still a lie</p>
<!--Compiler turns code into a running application-->
</section>
<section data-transition="none">
<h3 style="text-decoration: line-through">Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3 style="text-decoration: line-through">Def 2: Code => <i class="fa fa-magic" alt="compilation"></i> => Runnable Code</h3>
<h3>Def 3: Code => <i class="fa fa-magic" alt="compilation"></i> => Code Closer to Execution
<sup>*</sup>
</h3>
<p style="visibility: hidden"><sup>*</sup>Spacing</p>
</section>
<section data-transition="none">
<h3 style="text-decoration: line-through">Def 1: Code => <i class="fa fa-magic" alt="compilation"></i> => Running Application</h3>
<h3 style="text-decoration: line-through">Def 2: Code => <i class="fa fa-magic" alt="compilation"></i> => Runnable Code</h3>
<h3>Def 3: Code => <i class="fa fa-magic" alt="compilation"></i> => Code Closer to Execution <sup>*</sup></h3>
<p><sup>*</sup>Just kidding</p>
</section>
<section>
<h3>How do you generate code from code?</h3>
</section>
<section>
<img src="img/Ancient-Aliens.jpg" />
<h3 class="fragment">Abstract Syntax Trees</h3>
</section>
<section>
<h3>Parse Code => Create AST => Generate Code</h3>
<a href="https://astexplorer.net/">astexplorer.net</a>
</section>
<section>
<h3>TypeScript Input</h3>
<pre><code class="hljs" data-trim contenteditable>
/**
* Documentation for C
*/
class C {
/**
* constructor documentation
* @param a my parameter documentation
* @param b another parameter documentation
*/
constructor(a: string, b: C) { }
}
</code></pre>
<p>
Source: <a href="https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API">
TypeScript Compiler API Wiki
</a>
</p>
</section>
<section>
<h3>AST output</h3>
<pre><code class="hljs" data-trim contenteditable>
[
{
"name": "C",
"documentation": "Documentation for C ",
"type": "typeof C",
"constructors": [
{
"parameters": [
{
"name": "a",
"documentation": "my parameter documentation",
"type": "string"
},
{
"name": "b",
"documentation": "another parameter documentation",
"type": "C"
}
],
"returnType": "C",
"documentation": "constructor documentation"
}
]
}
]
</code></pre>
<p>
Source: <a href="https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API">
TypeScript Compiler API Wiki
</a>
</p>
</section>
<section>
<h2>Angular Compilation</h2>
</section>
<section>
<h3>What gets compiled?</h3>
<h3 class="fragment">TypeScript => TS/JS</h3>
<h3 class="fragment">Templates (HTML) => TS/JS</h3>
</section>
<section>
<h2>JIT Compilation</h2>
<ol>
<li class="fragment">TypeScript => JavaScript</li>
<li class="fragment">Transfer Application JS, Templates, Angular & Compiler to Client</li>
<li class="fragment">Bootstrap Application</li>
<li class="fragment">Parse Classes & Templates</li>
<li class="fragment">Generate Code</li>
<li class="fragment">Render Application</li>
</ol>
</section>
<section>
<h3>JIT Advantages</h3>
<ul>
<li>Out of the box</li>
<li>Faster for single compile cycle</li>
</ul>
<h3>Disadvantages</h3>
<ul>
<li>Must Transfer Compiler to Client</li>
<li>Compilation delay before render</li>
<li>Won't run in all environments</li>
</ul>
</section>
<section>
<h2>Generating code in the browser</h2>
<h3 class="fragment">String Concatination + Eval</h3>
</section>
<section>
<h2>Ahead of Time Compilation</h2>
</section>
<section>
<h2>AOT Compilation</h2>
<ol>
<li class="fragment">Parse Classes & Templates</li>
<li class="fragment">Generate Code (TypeScript)</li>
<li class="fragment">TypeScript => JavaScript</li>
<li class="fragment">Transfer Application JS & Angular to Client</li>
<li class="fragment">Bootstrap Application</li>
<li class="fragment">Render Application</li>
</ol>
</section>
<section>
<h3>AOT</h3>
<ul>
<li>
<h3>Advantages</h3>
<ul>
<li>Faster render times</li>
<li>Throws template errors early</li>
<li>Type checking in templates</li>
</ul>
</li>
<li>
<h3>Disadvantages</h3>
<ul>
<li>3rd party modules must include TypeScript or metadata</li>
<li>Code does not execute before generation</li>
<li>Generated templates larger than html. (Use lazy loading)</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Demo Benchmarks</h3>
</section>
<section>
<h3>Demo Compiled Template</h3>
</section>
<!--How to leverage each-->
<section>
<h1>Fun & Profit<h1>
</section>
<section>
<h2>Why do we even need to compile?</h2>
<h3 class="fragment">There's another compiler Angular is optimizing for...</h3>
</section>
<section>
<h2>JavaScript => Browser => V8 <i class="fa fa-magic" alt="compilation"></i> => Native Code => Application</h2>
<h3>Angular Optimizes for what the V8 engine's JIT compiler does best</h3>
</section>
<section>
<h3 class="fragment">Write TypeScript that is nice for humans</h3>
<h3 class="fragment">Compile to JavaScript that is nice for browsers</h3>
<h3 class="fragment">Compile to Native Code that is nice for processors</h3>
<h3 class="fragment">Profit.</h3>
</section>
<section>
<h2>Using AOT</h2>
</section>
<section>
<h2>AOT uses the NGC (Angular Compiler)</h2>
<h3 class="fragment">NGC compiles TypeScript to TypeScript, ES2015, ES5</h3>
<h3 class="fragment">With AOT it produces TypeScript</h3>
</section>
<section>
<h2>Option 1: Use NGC Directly</h2>
<ul>
<li>Add tsconfig-aot.json for AOT</li>
<li>index.html for AOT</li>
<li>Bootstrap using in main bootstrapModuleFactory</li>
<li>Add Rollup for tree shaking</li>
</ul>
</section>
<section>
<h2>Option 2: Leverage a Library</h2>
<h3>Angular Seed -> serve.prod.exp</h3>
<h3>Angular CLI -> ng serve -prod --aot</h3>
</section>
<section>
<h3>Review</h3>
<ul>
<li class="fragment">Compilation in General</li>
<li class="fragment">Compilation Cycle in Angular</li>
<li class="fragment">How to use AOT</li>
</ul>
</section>
<section>
<h2>References</h2>
<ul>
<li><a href="https://www.youtube.com/watch?v=kW9cJsvcsGo">Tobias Bosch explains the Angular Compiler</a></li>
<li><a href="https://angular.io/docs/ts/latest/cookbook/aot-compiler.html">AOT Compilation Cookbook</a></li>
<li><a href="https://github.com/mgechev/angular2-ngc-rollup-build">Simple AOT example</a></li>
<li><a href="https://github.com/mgechev/angular-seed">Angular Seed (Minko's Version)</a></li>
<li><a href="http://blog.mgechev.com/2016/08/14/ahead-of-time-compilation-angular-offline-precompilation/">Minko on Ahead-of-Time Compilation in Angular</a></li>
<li><a href="https://github.com/angular/angular-cli">Angular CLI</a></li>
</ul>
</section>
<section>
<h3>Want to explore a topic?</h3>
<h2 class="fragment">
Give a talk!
</h2>
</section>
<section>
<h2>The End</h2>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>