-
Notifications
You must be signed in to change notification settings - Fork 915
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
Tinygo wasm file bigger than from regular go? #2641
Comments
Can you put the tweaked version in a branch somewhere we can try it? |
Also, the -size option does give some space breakdown, but requires the wasi target. Try something like
|
Hi, thank you for your reply. I am trying to strip code of more/most deps ... to see if it makes any difference. The wasi option produces an os/signal error, even thought I don't see where I include that or parent library. If I don't figure out anything I will post stripped code online, but it's a little messy right now. Is it normal, that the compiler compiles for like half an hour (my codebase for the interpreter is not that big), or is this also the sign of the problem? |
At the moment, the compiler takes a lot longer than it should to run, especially when there are long init() functions. |
Hi, I removed all external dependencies, even the only really cruicial one (peg-parser yhirose/go-peg) and compiled. Tingo wasm file is now 6.7MB, go wasm file is 3.7 MB. I posted this code here: https://github.com/refaktor/rye/tree/tinygo-test-purged |
It should work just fine with any WebAssembly target. If it doesn't, I'd be interested in a bug report :) |
I misspoke, just meant "it works with the wasi target but not with no target specified". |
Build instructions are in main branch's README but seem somewhat garbled when they try to specify build tags.
so it's running into #1997. I suppose we could provide a stub runtime/trace for tinygo. But how did you get around that? |
Sorry, this is ad-hoc program removed of all dependencies. I didn't write any build instructions, I will add them. Basically, program doesn't yet use modules (longer story), so you need to do:
You don't need to run any of the go get commands since I removed all deps as far as I can see. And you don't need tags, so it should just be.
I compiled with -size full and got:
|
Ha, I was building main by accident. Works better if I actually build your branch :-) Building it not-for-wasm for the moment, just to see how big the binary is. Corrected instructions:
Go takes about 6 seconds to build; tinygo takes about 32 minutes. Result (roughly; actual commands maybe not quite as shown above):
and the size full output is like yours. rye/env alone is 2.3 MB, which is pretty impressive bloat for 60KB of source code. Does seem like something's fishy here. |
hm ... env/ is mostly mostly type definitions for various language objects and environment. The code is pretty usual I think. evaldo/ is the evaluator, and a bunch of builtin functions which could be more convoluted. It is not urgent to me to get this solved right now. I would love to use smaller WASM binary and have an example of tinygo option of course, but it's not a pressing issue. I could try even further remove code and see if I hit a big difference in output size at some specific point ... other than that I can't really help with the tinygo compiler :P |
I quickly scanned through it and also didn't see anything strange. Looks like pretty regular Go code to me. It certainly shouldn't blow up as it does at the moment. |
Someone could maybe look at the generated code. Alternately, removing part of the source of env and measuring the resulting reduction in generated code size might give us a hint which part of the code is getting bloated. Or removing code until the bloat goes away to find the smallest source tree that exhibits the awful bloat. |
So... I guess the slow bit is in llvm... |
I am trying to remove more code from env/ and recompile. I will let you know if I see any bigger change. |
@dkegel-fastly you could also try |
|
I removed some of the Objects in Rye, but it was linear reduction ... When I then removed some builtin functions (evaldo/builtins.go) which are defined as a map of objects, the reduction was larger. I now removed all builtin functions, to see if this huge map of objects/functions is problematic. Before removing all builtin functions in evaldo/ (tinygo.wasm file 6.4MB vs. go.wasm 3.7MB)
After removing all map[string]*env.Builtin from evaldo/ ... now sizes are comparable (tinygo.wasm file 2.1MB vs. go.wasm 2.4MB)
So this map could be a problem? Is this around the reduction I should expect / hope for, or should it be smaller still given that now program doesn't really import anything big and also doesn't do much practically :) ... I have no clue but that 800k at rye/env still seems a lot to me for a bunch of type definitions. I could further remove the code there and see. // edit: latest code is branch: tinygo-test-purged-2 https://github.com/refaktor/rye/tree/tinygo-test-purged-2 |
The line var builtins = map[string]*env.Builtin{ may be key to the slow compile times, though I still don't understand what's going on exactly. Try using lazy initialization of that instead of initializing it at init time. |
In the latest test (link to brach is up there) there were no more var builtins = map[string]*env.Builtin{ ... which did produce similar even a little smaller size of .wasm as regular Go compiler, but I think it still took a long time. I didn't measure it exactly. Otherwise, I wanted to not resort to code-generation too soon, so builtin functions are dynamically built now, hence this map[], but in future it might show better to have smart amount of codegen for builtin functions and they can then be statically defined, which might be better for the compiler? |
If you bring back the map, but only initialize it after main() starts, does that help the bloat problem? (I hear rumblings about fixing the speed problem with interp, but there's nothing solid to point to yet, and it may be a while.) |
I wonder if the |
Hi, I love what you are doing. I am making a programming language (https://github.com/refaktor/rye) in Go and I wanted to try compiling a stripped down version with tinygo, to see if it compiles. With some tweaking and removing various dependencies I managed to compile it, but it surprised me that the wasm file was 12MB in size, while wasm file compiled from regular go was 5MB. Tinygo compiles for really long time, but that doesn't bother me in this case.
Could it be that I did something wrong, os could some of the libraries I import be is somehow problematic? Is there a way to see or at least get a hint of what is taking so much space?
Best regards,
Janko
The text was updated successfully, but these errors were encountered: