-
Notifications
You must be signed in to change notification settings - Fork 951
Minimal compilation to WASM leaves some memory function artifacts #2491
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
Comments
What version of tinygo were you running this with? The |
This was on v0.21.0 darwin/amd64. Let me try building |
After cloning the package, checking out the
The result:
Basically the issue reproduces. ( The original compilation target's code:
|
Hmm. I was hoping the wasm-opt pass would handle some of that tree shaking. I'll investigate this a bit more. |
Part of this is related to panic handling. You can remove those passing |
That does improve things somewhat. Ran this: The file size went from around 1000 bytes to 555 bytes, and the quoted section becomes:
|
I have removed a few in #2549. At the moment we only really support WASI or browser environments, not stand alone environments. This might be something we could add though (with limitations such as not being able to use |
@aykevl : could you please clarify what you mean by 'stand alone environments'? I think that you mean that TinyGo isn't designed to support WASM files that only contain functions exported via the Of course such environments need to be embedded somewhere like a browser, so to me 'stand alone environment' can't be exclusive of an embedding browser or WASI environment. Thus my question. |
HI @aykevl |
freestanding seems to be the latest on getting this solved. #3068 @jzabinski-dolios if you agree, do you mind closing this out for that one, mainly as it is more elaborated and with a work-in-progress PR? |
Don't mind at all, thanks for asking |
I think this issue is slightly different. I agree the memory function artifacts are a problem. I have a fix for it here: #3142. It reduces binary size significantly for small binaries that don't allocate (and use |
New to TinyGo here.
I need a series of math functions in WebAssembly. These functions can all be called discretely by Javascript and they are completely self-sufficient: they need no other runtime features like garbage collection, debug information, etc. (They likely will not even need an import object defined in Javascript.)
I made a short example program,
findJD.go
.When I compile like this:
tinygo build -o tinygo.wasm -target=wasm -gc=none -scheduler=none -no-debug ./findJD.go
And then convert the WASM to WAT to look at the output (using another tool), I can see that the following is created (among other things):
Simply put, the only thing that I am going to actually use is:
For reference, if I write my example program in WAT by hand, compile it and convert back to WAT, I get:
I want to get as close to that simplicity as I can. How do I achieve this?
The text was updated successfully, but these errors were encountered: