Top Banner
Blazor: .NET in the browser with WebAssembly Bart Verkoeijen – @bgever 24 Nov 2018 – CodeConf Hong Kong
30

Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Oct 19, 2019

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Blazor: .NET in the browser with WebAssemblyBart Verkoeijen – @bgever 24 Nov 2018 – CodeConf Hong Kong

Page 2: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

JavaScript

The coding language for the web

Page 3: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Code for the web with high-level programming languages

WebAssembly(wasm)

Page 4: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Major languagessupported by WebAssembly

•C, C++, and Rust

•C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP

Page 5: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Supported in all major browsers

With asm.js supports also and other older browsers

Page 6: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

What are the benefits?

• Use your preferred language to target the web (no JS) • Leverage existing tools and libraries – portability • Paradigms like strong typing, functional programming, OOP • Better performance, faster startup time • Safe sand-boxed environment (browser's same-origin and permissions policies)

• JavaScript interop – complement rather than replace

Page 7: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Products using WebAssembly

Figma Google Earth SketchUp Soundation PSPDFKitUnity

Page 8: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Let’s dive deeper

Page 9: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Designed by a web standards team

• W3C Community Groupwww.w3.org/community/webassembly/Includes members of all major browsers

• W3C Working Groupwww.w3.org/wasm/

Page 10: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Progress

MVP• Binary module format for

execution• Feature parity with asm.js

After the MVP• Threads• Exception handling• Garbage Collection• ECMAScript module integration• …https://webassembly.org/docs/future-features/

Shipped in major browsersOct 2017

Page 11: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

How the compiler works

www.smashingmagazine.com/2017/05/abridged-cartoon-introduction-webassembly/

Page 12: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

How the compiler works

Page 13: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

How the compiler works

Page 14: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Resource loading

Page 15: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

At runtime – Initiating

WIP: <script type="module"> or ES2015 import, use loader script

// With streaming supportWebAssembly.instantiateStreaming( fetch('simple.wasm'), importObject).then(results => { /* Do something with the results! */ });

// WebAssembly 1.0 browsersfetch('module.wasm’).then(response => response.arrayBuffer()).then(bytes => WebAssembly.instantiate(bytes, importObject)).then(results => { /* Do something with the results! */ });

Page 16: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Demo: C to Wasm

Page 17: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Challenges

• No direct access to the DOM• Memory management – numeric• JS interop overhead• Tree shaking

• Early days – tooling in development• Debugging• Multi-treading• Source maps• Garbage collection (GC)

Page 18: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

.NET in the browser

Page 19: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

A story about SPA frameworks

Blazor

Yew

(.NET/C#)

(Rust)

Page 20: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Adding the missing pieces to Wasm

• DOM & Browser APIs• A component model for building

composable UI• Routing• Layouts• Forms and validation• Dependency injection• JavaScript interop

• Live reloading in the browser during development• Server-side rendering• Full .NET debugging both in

browsers and in the IDE• Rich IntelliSense and tooling• Ability to run on older (non-

WebAssembly) browsers via asm.js• Publishing and app size trimming

Page 21: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.
Page 22: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.
Page 23: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.
Page 24: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

An experiment: Blazor

• Jun 2017 Steve Sanderson showcases Blazor hacky experiment • Aug 2017

Mono project announces experimental WebAssembly compilation target • Nov 2017

Steve Sanderson switches Blazor to Mono runtime • Feb 2018

ASP.NET Team announces that they continue the experiment

Page 25: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

com/2018/02/06/blazor-intro/

Interpreted vs Ahead-of-Time (AOT)http://blog.stevensanderson.com/2018/02/06/blazor-intro/

Page 26: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Demo: Blazor

Page 27: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

A word about performanceBlazor is still an experiment

Your mileage may vary

Page 28: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Closing thoughts

Page 29: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Further reading

• WebAssembly www.webassembly.org • Lin Clark’s An Abridged Cartoon Introduction To WebAssembly

www.smashingmagazine.com/2017/05/abridged-cartoon-introduction-webassembly/ • Steve Sanderson’s first Blazor reveal www.youtube.com/watch?

v=MiLAE6HMr10 • Yew – Rust based SPA framework

github.com/DenisKolodin/yew • WebAssembly languages

github.com/appcypher/awesome-wasm-langs

Page 30: Blazor: .NET in the browser with WebAssembly · •C#/.NET, Go, D, Python, Java, Kotlin, Ruby, PHP. Supported in all major browsers With asm.js supports also and other older browsers.

Thanks for listening@bgever