Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore using tinygo to shrink browser wasm? #1111

Closed
Jarred-Sumner opened this issue Apr 4, 2021 · 3 comments
Closed

Explore using tinygo to shrink browser wasm? #1111

Jarred-Sumner opened this issue Apr 4, 2021 · 3 comments

Comments

@Jarred-Sumner
Copy link
Contributor

tinygo is a go compiler for embedded & wasm environments

It sounds like it could be interesting to shrink the wasm size and also maybe to improve runtime performance (but that is unclear, could be worse perf)

I spent about an hour trying to get esbuild to build & run via tinygo with little progress. I'm not very familiar with go's build system and I think its not correctly ignoring files that are supposed to be excluded by wasm (including when passing --tags=js wasm

Lots of standard library functions aren't implemented. It seems extremely tedious to get this to work.

At one point, I got something to build and it produced a 110 KB esbuild.wasm file -- which is big enough to indicate it has stuff in it and small enough to show promise versus 6 MB. But WebAssembly.instantiate would error with WebAssembly Instantiation: Import #0 module="module" error: module is not an object or function

Feel free to close if doesn't seem worthwhile to explore

@evanw
Copy link
Owner

evanw commented Apr 4, 2021

This has been brought up previously as well: #836 (comment). I don't think it'll work. From the TinyGo docs:

The recover builtin is not yet supported. Instead, a panic will always terminate a program and recover simply returns nil.

There are a few different places where esbuild relies on recover so TinyGo is not an option. They also say this:

Also, they have not been optimized for performance and will cause linear lookup times in some cases.

So I suspect that even if you did get it working, performance would also be worse since esbuild relies a lot on map lookups. That said, I have not tried it myself, so feel free to try it if you'd like. Just saying that I have a strong suspicion that it's not a worthwhile exploration.

@Jarred-Sumner
Copy link
Contributor Author

Makes sense

@aamironline
Copy link

aamironline commented Apr 12, 2022

Assumed, TinyGo won't support it (recover) due to the cost involved. However, instead of rejecting the TinyGo entirely, can't ESBuild use an alternate approach when the target compiler is TinyGo? In any case, it is always better to use channels or other signaling mechanisms to prevent dying thread, instead of panic and recover!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants