Skip to content
Set initial memory in wasm binaries
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


wams ("WebAssembly memory setter") is a command line utility written in Go that sets the initial number of memory pages of a WebAssembly (aka .wasm) binary file.


Since version Go version 1.11 it is possible to compile go sources to WebAssembly. This file contains bytecode that can be executed by browsers and by Node.js and other tools.

The initial results are both impressive and exciting but there are some pitfalls to be aware of. One major issue is the memory requirement of the .wasm file that the Go toolchain generates. The generated memory section requires the WebAssembly runtime to allocate 16384 64KB pages, that is 1GB of memory. Most of this memory is not used during execution but it seems as if a considerable amount is required for the initialization of the Go runtime. As a result, .wasm files generated by the Go compiler did not run on any of the Android devices we tested. They did run on desktops and iOS devices though.

wams allows to set the number of 64kB pages in the memory section of a .wasm file.


  • wams file.wasm

    • displays the initial memory size in 64KB pages and the file offset of the memory section in file.wasm
  • wams -pages 2048 -write file.wasm

    • patches the memory section in file.wasm to 2048 64KB pages


As of today (September 2018), reducing the number of pages did not suffice to run Go generated .wasm files on Android. The tested devices could allocate about 7500 pages but about 11000 pages were required to instantiate a small Go generated .wasm binary. However, the tool might be of use for other toochains when experimenting with initial page sizes.


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.