SlideShare a Scribd company logo
1 of 34
David Chang
DevOps@mithril
初探 Go-WebAssembly
What is WebAssembly
WebAssembly
● A new language for web
● Compiled from other
languages
● Offers maximized, reliable
performance
● Not replacing JS
A new language for web
● A low level language
● standard
● a binary instruction and a
assembly-like format
● Supported by Mozilla, Google,
Microsoft, Apple
WebAssembly Now
● Release 1.0
(Draft, last updated Dec 13,
2018)
● Experimental
Why WebAssembly
What’s wrong with JS?
Web Javascript
● Slow
● Insecure
● Dynamic type vs static type
● Avoid heavy computing in
Front-End
● Easy-writing
● Huge eco-system
Historical Javascript
● ECMAScript
-> by Brendan Eich in late 1995
● Internet Explorer 3
● NodeJS -> 2009
● npm -> 2010
JS is getting faster
● Just In Time compiler of JS
engine
● trace and re-optimize (loop)
● GC
● Built-in functions / Stadard
Library / APIs
But wasm is faster
https://hacks.mozilla.org/2017/02/w
hat-makes-webassembly-fast/
● Wasm is compiled
● No type assertion
● No need to re-optimize
● Much less GC
.go
.wasm
(IR)
Firefox x86
Assembly
spider
monkey
Chart Data Source Info
From WebAssembly to JS engine
https://mbebenita.github.io/WasmExplorer/
Some Examples
“Unleash the power of your web devices”
Wasm vs JS
github.com/shamadee/web-dsp
https://d2jta7o2zej4pf.cloudfront.net/
Epic Epic Zen Garden
Unreal Engine in WebAssembly and WebGL 2.0
https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.html
Go WebAssembly
From Go to web
Go-WebAssembly
● go 1.11 (Aug. 2018)
● Experimental feature
https://github.com/golang/go/wiki/W
ebAssembly
1.11 Release Note
Go 1.11 adds an experimental port to WebAssembly (js/wasm).
Go programs compile to one WebAssembly module
Go runtime for goroutine scheduling, garbage collection,
maps, etc.
Go programs can call into JavaScript using the new
experimental syscall/js package.
new GOOS "js" and GOARCH "wasm"
Why Go-WebAssembly
Again, why?
Go-WebAssembly
● Runs existing program / library
in Front-End
● Make golang protable
● Thread Safe
● Back-End to Full-Stack?
Let’s Go-WebAssembly
<html>
<head>
<meta charset="utf-8">
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(
fetch("main.wasm"),
go.importObject)
.then((result) => {
go.run(result.instance);
});
</script>
</head>
<body></body>
</html>
run-%:
GOOS=js GOARCH=wasm
go run -exec="$(shell go env
GOROOT)/misc/wasm/go_js_wasm_exec" ./src/$*
test:
GOOS=js GOARCH=wasm
go test -exec="$(shell go env GOROOT)/misc/wasm/go_js_wasm_exec" ./...
build-%:
GOOS=js GOARCH=wasm
go build -o public/lib.wasm ./src/$*
server:
go run ./src/server -listen :8080 -dir public
.go .wasm JS API
Engine
Chart Data Source Info
From Golang to Web
Compile golang functions to wasm, and runs in JS
package main
import (
"strconv"
"syscall/js"
)
func add(i []js.Value) {
doc := js.Global().Get("document")
value1 := doc.Call("getElementById", "input1").Get("value").String()
value2 := doc.Call("getElementById", "input2").Get("value").String()
int1, _ := strconv.Atoi(value1)
int2, _ := strconv.Atoi(value2)
doc.Call("getElementById", "sum").Set("value", int1+int2)
}
// JS
func add() {
var value1 = document.getElementById("input1").value;
vat value2 = document.getElementById("input2").value;
document.getElementById("sum").value = Number(value1) + Number(value2);
}
// Go
func add(i []js.Value) {
doc := js.Global().Get("document")
value1 := doc.Call("getElementById", "input1").Get("value").String()
value2 := doc.Call("getElementById", "input2").Get("value").String()
int1, _ := strconv.Atoi(value1)
int2, _ := strconv.Atoi(value2)
doc.Call("getElementById", "sum").Set("value", int1+int2)
}
Pacakge syscall/js
● Bumpy when manipulate DOM
● access WebAssembly host
environment using the
js/wasm architecture
● API is based on JavaScript
semantics.
● EXPERIMENTAL
func main() {
c := make(chan struct{}, 0)
println("WASM Go Initialized")
// register functions
registerCallbacks()
<-c
println("Callbacks registered.") // console.log
}
func registerCallbacks() {
js.Global().Set("add", js.NewCallback(add))
js.Global().Set("subtract", js.NewCallback(subtract))
}
Use Go as Modules
● Import Go packages
● Complie to .wasm
● Register functions as JS
callbacks
● Invoke functions in JS
● Leave the DOMs to JS
Benefits from Go-wasm
● Runs existing program / library
in Front-End
● Make golang protable
● Thread Safe
● Join .wasm from other
languages
Go-Wasm Examples
https://justinclift.github.io/wasmGraph1/
GameBoyColor-Wasm
https://github.com/djhworld/gomeboycolor-wasm
Move Back-End Front
Performance no longer a problem. What you want to run in browser?
kubernetes, kubectl, geth...
Lin Clark: A Cartoon Intro to WebAssembly | JSConf EU 2017
https://www.youtube.com/watch?v=HktWin_LPf4
https://hacks.mozilla.org/2017/02/a-cartoon-intro-to-webassembly/
Dan Callahan: Practical WebAssembly | JSConf Budapest 2017
https://www.youtube.com/watch?v=bac0dGQbUto
Using WebAssembly and Threads (Chrome Dev Summit 2018)
https://www.youtube.com/watch?v=zgOGZgAPUjQ
Watch Lin Clark cartoon if you only have 30 mins!
Q&A

More Related Content

What's hot

Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs Irfan Maulana
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
Webpack
Webpack Webpack
Webpack DataArt
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An IntroductionNirvanic Labs
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with WebpackJake Peyser
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundlerAndrea Giannantonio
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBHengki Sihombing
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptLars Thorup
 
Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerMohammed Arif
 
JavaScript Engine and WebAssembly
JavaScript Engine and WebAssemblyJavaScript Engine and WebAssembly
JavaScript Engine and WebAssemblyChanghwan Yi
 
Node.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScriptNode.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScriptTom Boutell
 
Advanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsk88hudson
 

What's hot (20)

Hey webpack
Hey webpackHey webpack
Hey webpack
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Webpack: from 0 to 2
Webpack: from 0 to 2Webpack: from 0 to 2
Webpack: from 0 to 2
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Webpack
Webpack Webpack
Webpack
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An Introduction
 
Node.js with Express
Node.js with ExpressNode.js with Express
Node.js with Express
 
Bundle your modules with Webpack
Bundle your modules with WebpackBundle your modules with Webpack
Bundle your modules with Webpack
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
 
CasperJS
CasperJSCasperJS
CasperJS
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
Grunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
JavaScript Engine and WebAssembly
JavaScript Engine and WebAssemblyJavaScript Engine and WebAssembly
JavaScript Engine and WebAssembly
 
Node.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScriptNode.js 201: building real-world applications in pure JavaScript
Node.js 201: building real-world applications in pure JavaScript
 
What grunt?
What grunt?What grunt?
What grunt?
 
Advanced front-end automation with npm scripts
Advanced front-end automation with npm scriptsAdvanced front-end automation with npm scripts
Advanced front-end automation with npm scripts
 

Similar to Intro to go web assembly

Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest servicesIoan Eugen Stan
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)jeresig
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end WorkflowPagepro
 
Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Dirk Ginader
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web AppsTimothy Fisher
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Devfest09 Cschalk Gwt
Devfest09 Cschalk GwtDevfest09 Cschalk Gwt
Devfest09 Cschalk GwtChris Schalk
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblyAll Things Open
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build Systemklipstein
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websitesoazabir
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2JooinK
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 

Similar to Intro to go web assembly (20)

Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)New Features Coming in Browsers (RIT '09)
New Features Coming in Browsers (RIT '09)
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!Let Grunt do the work, focus on the fun!
Let Grunt do the work, focus on the fun!
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Grails 101
Grails 101Grails 101
Grails 101
 
Why Gradle?
Why Gradle?Why Gradle?
Why Gradle?
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Devfest09 Cschalk Gwt
Devfest09 Cschalk GwtDevfest09 Cschalk Gwt
Devfest09 Cschalk Gwt
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssembly
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build System
 
7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites7 tips for javascript rich ajax websites
7 tips for javascript rich ajax websites
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 

More from Che-Chia Chang

COSCUP Scouter: Face recognizer retrieves your Github contribution
COSCUP Scouter: Face recognizer retrieves your Github contributionCOSCUP Scouter: Face recognizer retrieves your Github contribution
COSCUP Scouter: Face recognizer retrieves your Github contributionChe-Chia Chang
 
Elk for applications on k8s
Elk for applications on k8sElk for applications on k8s
Elk for applications on k8sChe-Chia Chang
 
Automated container-deployment-on-kubernetes
Automated container-deployment-on-kubernetesAutomated container-deployment-on-kubernetes
Automated container-deployment-on-kubernetesChe-Chia Chang
 
Deploy High Availability Kubernetes with Kubespray
Deploy High Availability Kubernetes with KubesprayDeploy High Availability Kubernetes with Kubespray
Deploy High Availability Kubernetes with KubesprayChe-Chia Chang
 
K8s storage-glusterfs-20180210
K8s storage-glusterfs-20180210K8s storage-glusterfs-20180210
K8s storage-glusterfs-20180210Che-Chia Chang
 

More from Che-Chia Chang (8)

COSCUP Scouter: Face recognizer retrieves your Github contribution
COSCUP Scouter: Face recognizer retrieves your Github contributionCOSCUP Scouter: Face recognizer retrieves your Github contribution
COSCUP Scouter: Face recognizer retrieves your Github contribution
 
Elk for applications on k8s
Elk for applications on k8sElk for applications on k8s
Elk for applications on k8s
 
Gdg devfest-2018
Gdg devfest-2018Gdg devfest-2018
Gdg devfest-2018
 
CRI, OCI, and CRI-O
CRI, OCI, and CRI-OCRI, OCI, and CRI-O
CRI, OCI, and CRI-O
 
Kubernetes networks
Kubernetes networksKubernetes networks
Kubernetes networks
 
Automated container-deployment-on-kubernetes
Automated container-deployment-on-kubernetesAutomated container-deployment-on-kubernetes
Automated container-deployment-on-kubernetes
 
Deploy High Availability Kubernetes with Kubespray
Deploy High Availability Kubernetes with KubesprayDeploy High Availability Kubernetes with Kubespray
Deploy High Availability Kubernetes with Kubespray
 
K8s storage-glusterfs-20180210
K8s storage-glusterfs-20180210K8s storage-glusterfs-20180210
K8s storage-glusterfs-20180210
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 

Intro to go web assembly

  • 3. WebAssembly ● A new language for web ● Compiled from other languages ● Offers maximized, reliable performance ● Not replacing JS
  • 4. A new language for web ● A low level language ● standard ● a binary instruction and a assembly-like format ● Supported by Mozilla, Google, Microsoft, Apple
  • 5. WebAssembly Now ● Release 1.0 (Draft, last updated Dec 13, 2018) ● Experimental
  • 7. Web Javascript ● Slow ● Insecure ● Dynamic type vs static type ● Avoid heavy computing in Front-End ● Easy-writing ● Huge eco-system
  • 8. Historical Javascript ● ECMAScript -> by Brendan Eich in late 1995 ● Internet Explorer 3 ● NodeJS -> 2009 ● npm -> 2010
  • 9. JS is getting faster ● Just In Time compiler of JS engine ● trace and re-optimize (loop) ● GC ● Built-in functions / Stadard Library / APIs
  • 10. But wasm is faster https://hacks.mozilla.org/2017/02/w hat-makes-webassembly-fast/ ● Wasm is compiled ● No type assertion ● No need to re-optimize ● Much less GC
  • 11. .go .wasm (IR) Firefox x86 Assembly spider monkey Chart Data Source Info From WebAssembly to JS engine https://mbebenita.github.io/WasmExplorer/
  • 12. Some Examples “Unleash the power of your web devices”
  • 14. Epic Epic Zen Garden Unreal Engine in WebAssembly and WebGL 2.0 https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGarden.html
  • 16. Go-WebAssembly ● go 1.11 (Aug. 2018) ● Experimental feature https://github.com/golang/go/wiki/W ebAssembly
  • 17. 1.11 Release Note Go 1.11 adds an experimental port to WebAssembly (js/wasm). Go programs compile to one WebAssembly module Go runtime for goroutine scheduling, garbage collection, maps, etc. Go programs can call into JavaScript using the new experimental syscall/js package. new GOOS "js" and GOARCH "wasm"
  • 19. Go-WebAssembly ● Runs existing program / library in Front-End ● Make golang protable ● Thread Safe ● Back-End to Full-Stack?
  • 21. <html> <head> <meta charset="utf-8"> <script src="wasm_exec.js"></script> <script> const go = new Go(); WebAssembly.instantiateStreaming( fetch("main.wasm"), go.importObject) .then((result) => { go.run(result.instance); }); </script> </head> <body></body> </html>
  • 22. run-%: GOOS=js GOARCH=wasm go run -exec="$(shell go env GOROOT)/misc/wasm/go_js_wasm_exec" ./src/$* test: GOOS=js GOARCH=wasm go test -exec="$(shell go env GOROOT)/misc/wasm/go_js_wasm_exec" ./... build-%: GOOS=js GOARCH=wasm go build -o public/lib.wasm ./src/$* server: go run ./src/server -listen :8080 -dir public
  • 23. .go .wasm JS API Engine Chart Data Source Info From Golang to Web Compile golang functions to wasm, and runs in JS
  • 24. package main import ( "strconv" "syscall/js" ) func add(i []js.Value) { doc := js.Global().Get("document") value1 := doc.Call("getElementById", "input1").Get("value").String() value2 := doc.Call("getElementById", "input2").Get("value").String() int1, _ := strconv.Atoi(value1) int2, _ := strconv.Atoi(value2) doc.Call("getElementById", "sum").Set("value", int1+int2) }
  • 25. // JS func add() { var value1 = document.getElementById("input1").value; vat value2 = document.getElementById("input2").value; document.getElementById("sum").value = Number(value1) + Number(value2); } // Go func add(i []js.Value) { doc := js.Global().Get("document") value1 := doc.Call("getElementById", "input1").Get("value").String() value2 := doc.Call("getElementById", "input2").Get("value").String() int1, _ := strconv.Atoi(value1) int2, _ := strconv.Atoi(value2) doc.Call("getElementById", "sum").Set("value", int1+int2) }
  • 26. Pacakge syscall/js ● Bumpy when manipulate DOM ● access WebAssembly host environment using the js/wasm architecture ● API is based on JavaScript semantics. ● EXPERIMENTAL
  • 27. func main() { c := make(chan struct{}, 0) println("WASM Go Initialized") // register functions registerCallbacks() <-c println("Callbacks registered.") // console.log } func registerCallbacks() { js.Global().Set("add", js.NewCallback(add)) js.Global().Set("subtract", js.NewCallback(subtract)) }
  • 28. Use Go as Modules ● Import Go packages ● Complie to .wasm ● Register functions as JS callbacks ● Invoke functions in JS ● Leave the DOMs to JS
  • 29. Benefits from Go-wasm ● Runs existing program / library in Front-End ● Make golang protable ● Thread Safe ● Join .wasm from other languages
  • 32. Move Back-End Front Performance no longer a problem. What you want to run in browser? kubernetes, kubectl, geth...
  • 33. Lin Clark: A Cartoon Intro to WebAssembly | JSConf EU 2017 https://www.youtube.com/watch?v=HktWin_LPf4 https://hacks.mozilla.org/2017/02/a-cartoon-intro-to-webassembly/ Dan Callahan: Practical WebAssembly | JSConf Budapest 2017 https://www.youtube.com/watch?v=bac0dGQbUto Using WebAssembly and Threads (Chrome Dev Summit 2018) https://www.youtube.com/watch?v=zgOGZgAPUjQ Watch Lin Clark cartoon if you only have 30 mins!
  • 34. Q&A

Editor's Notes

  1. Runs in javascript engines
  2. Slow: type assertion, parse, execute, requires lots of optimization Insecure: memory control
  3. Designed for web
  4. Slow: type assertion, parse, execute, requires lots of optimization
  5. Near machine code performance
  6. Runs in javascript engines
  7. Go
  8. The WebAssembly.instantiateStreaming() function compiles and instantiates a WebAssembly module directly from a streamed underlying source. This is the most efficient, optimized way to load wasm code.
  9. Go