by kodablah · 5y ago · 0 comments
I also did basically this exact same thing for Go [0] when I realized their initialization in WASM was very heavy[1]. Basically I ran up until the real Go main started which includes a ton of runtime package/data initialization, and took a snapshot of the data and baked it back into the WASM and removed all the pre-main code. Granted this was years ago so I don't know if it still works on generated code today, but the idea is the same.
I think languages compiling to WASM, if they can, should run their initialization code and snapshot the data. A lot of people don't realize the number of init instructions to bootstrap a runtime these days. Go alone has thousands of instructions just to initialize the unicode tables. Over 4 million instructions before main were removed from hello-world Go WASM init by pre-processing.
0 - https://github.com/cretz/go-wasm-bake 1 - https://github.com/golang/go/issues/26622
It gets a bit worse if your initialization code is doing a lot of dynamic allocation, as you're shipping
Unless maybe you're managing cache yourself with a service worker.
(Not sure if that's the best link, but it is easily Googleable.)
Generally, I’d say that dumping VM state (if not in the host executable format) is a perfectly ordinary thing for an isolated VM to do. It’s the default way Smalltalk systems operate, for example, being very close ideologically to Lisp machines in that they try to be an OS centered around a programming language more than a programming language implemented inside an OS.
(I should really look into that Oberon thing one of those days...)
Recently Emacs has moved to a "portable dump" approach which saves the heap snapshot separately.
https://web.archive.org/web/20191030205003/https://dancol.or...