-
Notifications
You must be signed in to change notification settings - Fork 28
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
Comparison with a Rust WASI binary #2135
Comments
Thanks for raising this issue. Unfortunately, the Swift compiler doesn't run all of the required size optimizations yet, but you can run them manually with I need to have a closer look at the benchmark to understand what other optimizations are missing to make performance comparable with the Rust version. |
Thanks for your help, @MaxDesiatov. Although |
@hassan-shahbazi I've reviewed the benchmark and it looks like Wasmer's I'd recommend that you pre-compile the Until Wasmer improves their compilation speed, or until #7 is resolved on our side, I recommend that you use |
Some of the size is inherit to Swift packaging it's stdlib and ARC? Given Rust's fine-tuned memory control via ownership, Swift will likely permeate overhead in-comparison - though expressing one's application in Swift has it's benefits over Rust for a large pool of developers. @MaxDesiatov with appropriate Swift compiler optimizations, do you have any notion of the theoretical smallest size for a Swift hello world function compiled to WASM? I believe WASM-specific experiments like AssemblyScript produce the smallest sizes and Rust due to a number of factors also produces relatively small .wasm files. |
I don't think ARC has any relation to the size of the binary. With the latest development snapshots I think we can DCE unused parts of stdlib, so it's up to a user whether they rely on stdlib and bear the cost. If they won't use it, we'll strip it out. The biggest overhead in binary size currently comes from ICU and WASI. As far as I understand, we either need to find a way to replace ICU with something smaller, or eliminate it completely. As for WASI, I think we only rely on allocators from it, we potentially can drop WASI as soon as we have custom allocators. These are the biggest parts of the overhead that I currently know of. As soon as they're eliminated, I don't see why a simple "Hello world" binary written in Swift should be bigger than one produced by Rust or AssemblyScript. As for more complex cases, it again depends on what code developers bring in. If binary size is important to a developer, they should do size profiling regardless of what language they use. |
Precisely, the size of stdlib is not optimized yet because the current toolchain doesn't provide prebuilt sib and swiftmodulesummary. I have to update build script to distribute them within our toolchain and implement file search mechanism for those supplementary files. |
Thanks for the comment, @MaxDesiatov. Updating to wasm-5.3.1-RELEASE and by refactoring the code so the binary is compiled only once, I've got a better performance comparable to Rust. UpdateThe verbose log shows the problem is probably with the wasmer compile performance rather than executing the binary. $ binary=rust go test ./... -v -race -count 1 -run _Rust
=== RUN TestStartBinary_Rust
Hello, world!
--- PASS: TestStartBinary_Rust (0.00s)
=== RUN TestExportedFunction_Rust
--- PASS: TestExportedFunction_Rust (0.00s)
=== RUN TestImportedFunction_Rust
--- PASS: TestImportedFunction_Rust (0.00s)
PASS
ok github.com/hassan-shahbazi/swiftwasi/src 0.118s
$ binary=swift go test ./... -v -race -count 1 -run _Swift
=== RUN TestStartBinary_Swift
Hello World!
--- PASS: TestStartBinary_Swift (0.00s)
=== RUN TestExportedFunction_Swift
--- PASS: TestExportedFunction_Swift (0.00s)
=== RUN TestImportedFunction_Swift
--- PASS: TestImportedFunction_Swift (0.00s)
PASS
ok github.com/hassan-shahbazi/swiftwasi/src 3.401s |
Compared to a Rust generated binary, swiftwasm generates binaries with slower performance and larger size. The results can be evaluated here: https://github.com/hassan-shahbazi/swiftwasm-go/tree/benchmark
Performance
With the same imported and exported functions and the _start, Swift's binary performs almost 85x slower than the Rust one, with
18.350
seconds and0.214
seconds respectively.Size
In addition to performance, I can see Swift generated binary is almost 5x larger than the Rust generated binary
The text was updated successfully, but these errors were encountered: