Slide 1

Slide 1 text

The State of AssemblyScript 2018 Emscripten & WebAssembly Night #6 2018.12.14 @kazupon

Slide 2

Slide 2 text

Who am I ?


Slide 3

Slide 3 text

CTO
 Vue.js Core Team Vue.js japan users group organizer vue-i18n author WebAssembly Love ❤ @kazu_pon kazupon kazupon

Slide 4

Slide 4 text

Introduction

Slide 5

Slide 5 text

Last a year …

Slide 6

Slide 6 text

https://qiita.com/chikoski/items/d98ed0a98acfa896869f

Slide 7

Slide 7 text

https://qiita.com/kazupon/items/37e1ee9db0ca5419c517

Slide 8

Slide 8 text

One year has passed.

Slide 9

Slide 9 text

During this time, AssemblyScript evolves little by little.

Slide 10

Slide 10 text

Today Contents
 
 About recently updates of AssemblyScript

Slide 11

Slide 11 text

ATTENTION !! • AssemblyScript v5 is WIP
 (Not published in NPM) • It might be changed in future

Slide 12

Slide 12 text

What is AssemblyScript?

Slide 13

Slide 13 text

Compile a strictly-typed subset of TypeScript to WebAssembly

Slide 14

Slide 14 text

Recently updates from last year

Slide 15

Slide 15 text

Hot topics •Memory management •AssemblyScript loader •GC Implementation

Slide 16

Slide 16 text

Memory Management

Slide 17

Slide 17 text

Kind of allocators • allocator/arena • allocator/tlsf • allocator/buddy • allocator/system HEAP_BASE (the first 8 byte aligned offset after static) Static Heap Memory

Slide 18

Slide 18 text

• Accumulates memory with no mechanism to free specific segments allocator/arena Static Allocated memory.allocate(1024) startOffset offset 64KB (page x) Allocatable Heap region Memory

Slide 19

Slide 19 text

• Simply increase the memory size, when memory size will be about to fill. allocator/arena Static Allocated memory.allocate(1024) startOffset offset 64KB Memory memory.grow(2) 128KB

Slide 20

Slide 20 text

• when memory.reset, resets the counting memory offset to its initial value and starts all over again. allocator/arena Static Heap memory.reset() startOffset offset 128KB Memory 64KB

Slide 21

Slide 21 text

allocate / free of memory

Slide 22

Slide 22 text

• You can use your custom memory allocator ! allocator/system

Slide 23

Slide 23 text

Memory Layout • String
 e.g. const str: string = ‘Hello’

Slide 24

Slide 24 text

Memory Layout • Arrays: All arrays store their contents in an ArrayBuffer behind the scenes.

Slide 25

Slide 25 text

Memory Layout • ArrayBuffer layout

Slide 26

Slide 26 text

AssemblyScript loader

Slide 27

Slide 27 text

What is it? • Provide some APIs of convenient AssemblyScript modules loading • Demangles module • Exports to a friendly object structure compatible WebIDL and TypeScript definitions for JS env • Some useful utilities as helper API, to read/write data from/to memory

Slide 28

Slide 28 text

Demangles module structure add Point thisPtr x (getter/setter) y (getter/setter) add (method) I8 U8 I16 U16 I32 U32 I64 U64 F32 F64 Static Heap WASM module Demangles module Wrap Wrap Return the pointer Memory Ref newString getString … Utilities

Slide 29

Slide 29 text

How to use demangles module Static Heap Memory 32 64 0x00010000 p1 0x00010008 thisPtr 0x00010000 x y pass the pointer pass the pointer 0x00000000

Slide 30

Slide 30 text

Working with strings and arrays • ex: object path parser

Slide 31

Slide 31 text

Reading/writing basic values to/from memory https://github.com/AssemblyScript/assemblyscript/tree/master/lib/loader#readingwriting-basic-values-tofrom-memory Static Heap Memory FF FF 0x00010000 ptr: 0x00010000 0x00010001 U8 0x00000000 U16

Slide 32

Slide 32 text

GC implementation

Slide 33

Slide 33 text

Experimental !! https://github.com/AssemblyScript/assemblyscript/pull/196

Slide 34

Slide 34 text

Manually GC release

Slide 35

Slide 35 text

GC related issues • GC experimentation • GitHub Issue Number: #89 • Implement reference counting and/or garbage collection • GitHub Issue Number: #16

Slide 36

Slide 36 text

In future …

Slide 37

Slide 37 text

Status / Roadmap • Standard library comatibility • TypeScript comatiplity • WASM features • Managed object runtime https://next.assemblyscript.org/#/development/roadmap

Slide 38

Slide 38 text

Closing

Slide 39

Slide 39 text

Closing •AssemblyScript is steadily evolving •Memory management •AssemblyScript loader •GC Implementation •It has a potential as WASM app implementation language!

Slide 40

Slide 40 text

Thanks!