Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The State of AssemblyScript 2018

38bee248082f6071230de65e9d74a944?s=47 kazupon
December 14, 2018

The State of AssemblyScript 2018



December 14, 2018

More Decks by kazupon

Other Decks in Programming


  1. The State of AssemblyScript 2018 Emscripten & WebAssembly Night #6

    2018.12.14 @kazupon
  2. Who am I ?

  3. CTO
 Vue.js Core Team Vue.js japan users group organizer vue-i18n

    author WebAssembly Love ❤ @kazu_pon kazupon kazupon
  4. Introduction

  5. Last a year …

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

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

  8. One year has passed.

  9. During this time, AssemblyScript evolves little by little.

  10. Today Contents
 About recently updates of AssemblyScript

  11. ATTENTION !! • AssemblyScript v5 is WIP
 (Not published in

    NPM) • It might be changed in future
  12. What is AssemblyScript?

  13. Compile a strictly-typed subset of TypeScript to WebAssembly

  14. Recently updates from last year

  15. Hot topics •Memory management •AssemblyScript loader •GC Implementation

  16. Memory Management

  17. Kind of allocators • allocator/arena • allocator/tlsf • allocator/buddy •

    allocator/system HEAP_BASE (the first 8 byte aligned offset after static) Static Heap Memory
  18. • 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
  19. • 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
  20. • 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
  21. allocate / free of memory

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

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

  24. Memory Layout • Arrays: All arrays store their contents in

    an ArrayBuffer behind the scenes.
  25. Memory Layout • ArrayBuffer layout

  26. AssemblyScript loader

  27. 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
  28. 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
  29. How to use demangles module Static Heap Memory 32 64

    0x00010000 p1 0x00010008 thisPtr 0x00010000 x y pass the pointer pass the pointer 0x00000000
  30. Working with strings and arrays • ex: object path parser

  31. 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
  32. GC implementation

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

  34. Manually GC release

  35. GC related issues • GC experimentation • GitHub Issue Number:

    #89 • Implement reference counting and/or garbage collection • GitHub Issue Number: #16
  36. In future …

  37. Status / Roadmap • Standard library comatibility • TypeScript comatiplity

    • WASM features • Managed object runtime https://next.assemblyscript.org/#/development/roadmap
  38. Closing

  39. Closing •AssemblyScript is steadily evolving •Memory management •AssemblyScript loader •GC

    Implementation •It has a potential as WASM app implementation language!
  40. Thanks!