days
-4
-5
hours
-2
-1
minutes
-2
-6
seconds
0
-4
search
Getting smaller and smaller

How small can TinyGo squeeze down WebAssembly?

Sarah Schlothauer
© Shutterstock / ongarj boonpho

Since we covered TinyGo last year, it has expanded its reach and seen several updates. This Go compiler for microcontrollers, modern web browsers, and command-line tools also can compile Go to WebAssembly to create browser-based apps. How small can TinyGo squeeze down WebAssembly and what drawbacks and limitations does it have?

TinyGo is a Go compiler for small places, including microcontrollers, modern web browsers, and command-line tools. It can also compile Go to WebAssembly (WASM) in order to create browser-based apps. So, just how small can you squeeze a gopher down?

When we first covered TinyGo last year, the project did not yet support WASM for browsers. Now, let’s take a look at how this project has grown, what changes it has made, and what developers are doing with the teeny-tiny Golang tool.

Fitting Go into small places. Source.

Current release

The current project release is version 0.60, updated on May 29, 2019. This release added some portability improvements to the command line, enhancements to help improve code quality, and fixed some bugs.

TinyGo has expanded its range and now supports 14 boards:

Driver support for 26 sensors and devices also available.

Squeezing down WebAssembly with TinyGo

Developer Sendil Kumar N has been running a series of regarding WASM performance optimizations using TinyGo. How much can you squeeze out of WebAssembly?

SEE ALSO: JavaScript or WebAssembly: Is WASM the superhero JS needs?

With the help of TinyGo, he has been able to reduce WebAssembly binaries by 72%.

According to his blog, he has achieved this reduction from 56kB, to 26 kB, all the way down to 16kB.

Potential limitations

Some of the previously discussed drawbacks still remain, however. Most notably, TinyGo does not support garbage collection on a majority of microcontrollers.

From the documentation:

While not directly a language feature (the Go spec doesn’t mention it), garbage collection is important for most Go programs to make sure their memory usage stays in reasonable bounds.

Garbage collection is currently only supported on ARM microcontrollers (Cortex-M). For this platform, a simple conservative mark-sweep collector has been implemented. Other platforms will just allocate memory without ever freeing it.

Careful design may avoid memory allocations in main loops. You may want to compile with -gc=noneand look at link errors to find out where allocations happen: the compiler inserts calls to runtime.alloc to allocate memory. For more information, see heap allocation.

https://tinygo.org/lang-support/

SEE ALSO: Golang grows in the enterprise: Half of users program with Go daily

Because of this GC limitation, WebAssembly projects made with TinyGo may face some memory usage hurdles, no matter how small they are.

Support for goroutines is still also considered experimental in the current build of TinyGo. The doc states, “simple programs usually work”.

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of