4 ms·
Go binary size makes it not an option for wasm.
by Touche 5y ago
Go binary size makes it not an option for wasm.
- gen220 5y agoThere are go variants for this. See tinygo [1], which targeted embedded originally (iirc) but now also targets wasm. So you’re definitely correct that core Go is not an option, but options exist within the “greater metropolitan area” that’s built up around downtown. These are among the benefits of having a relatively simple language and a 1.0 compatibility commitment, I think. [1]: https://tinygo.org/ https://tinygo.org/ their FAQ is quite good.
- oefrha 5y agoTinygo is severely limited, e.g. it doesn't support encoding/json. Want to deal with any JSON API, or anything that indirectly uses JSON serialization? Forget about it. A current side project of mine uses golang's wasm. Not a big codebase, but the wasm is 2.7MB brotli'ed. Certainly huge to me (I'm sure it's almost in the lean and mean camp compared to the average website today, though).
- gray_-_wolf 5y agoencoding/json sucks anyway, so using something 3rd party would likely be better option anyway
- wlll 5y agoHow so?
- gen220 5y agoI think it’s well demonstrated to be slow (ns/op) and wasteful (allocs/op) in benchmarks, especially in bigger payloads. The HTTP library is similar. Most 3rd party libs make some trade offs that are pretty reasonable to achieve superior perf, but it’s worth understanding them to make sure it’s best for your use case.
- gray_-_wolf 5y agoI've run into few issues: 1. Performance: lot of reflection and allocations, so not the fastest thing ever. 2. Case insensitivity: https://play.golang.org/p/LtwChO_tp0 https://play.golang.org/p/LtwChO_tp0 this can be pretty unpleasant when it bites you 3. Unicode: It replaces invalid utf8 with unicode questions marks (dunno how exactly is the replacement character called) but does not provide any API to detect that it happened. So that can lead to silent corruption of the data.
- wlll 5y ago3. in my mine makes it totally unusable, I didn't know that, glad I do now! 1. and 2. I could likely live with, but aren't great.
- gen220 5y agoYeah, tinygo was originally intended for embedded, so the good news is that many significant wasm binary size optimizations are still to come, I think. Today, there are ways to get the binary smaller, but they involve avoiding certain libraries or preferring certain implementations of common libraries over others. It’s definitely an art that requires conscientious practice these days. A run of the mill go application will not compile down to a tiny wasm with tinygo, without refactoring. But it’s possible. Like I said, it’s on the outskirts, not downtown. Still within reach at least.
- sagichmal 5y agoTinyGo will soon support encoding/json.
- speedgoose 5y agoI tried tinygo on web assembly. I very quickly decided to use Rust instead.
- deleted 5y ago[deleted]
- patrickaljord 5y agoWhy not? If you use wasm for a small library need in your web app, then sure, go doesn't make sense. But if your whole app is coded in wasm like a game, then it's probably ok I guess as the app will be heavy to load regardless.
- Touche 5y agoOk, sure. If Go wasm is only useful for games... and I'm pretty sure game developers are picking C++ or Rust, then that's a severe limitation.