-
Notifications
You must be signed in to change notification settings - Fork 248
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
Investigate reported size discrepancy between Rust and AssemblyScript contracts #167
Comments
Created size analysis tool at https://github.com/near/wasm_sizer. Doesn't work properly on AssemblyScript files yet due to decoding library bug. Filed bug athre0z/wasm#7 |
Reachability analysis for ten largest functions in regular build of https://github.com/olonho/voting-app/blob/master/contract/src/lib.rs and after application of |
Just compiled the assemblyscript counter: https://github.com/near-examples/counter with
and the resulting binary is 18K. Then compiled https://github.com/near-examples/rust-counter Initially got 41K. Then Then I returned to the assemblyscript. The unoptimized was 30K, but with the above Then when I passed the optimized AS binary to Now I'm going to use @olonho's new tool to investigate further. |
@olonho I found that for assemblyscript binaries if I use Furthermore, the AS compiler also outputs a |
I guess it's because wasm-dis -> wasm-as loose a lot of debug and sourcemap info. If you disable sourcemapping on AS it could be also small I guess. Also you could add |
Hmm it wasn't compiled with source maps, but |
Ah, ok |
After removing the debug flag and doing |
@olonho Removing the |
So after inspecting the Rust counter's source, I realized it differs from the AssemblyScript as its increment/decrement functions don't take an amount parameter. After adding this to the contract, the rust binary became 100K and optimized to 85K. |
@willemneal Are you saying Rust contract went from 41K to 100K after adding arguments? If that's true then it seems like |
Yep exactly. So it's serde_json for sure. |
|
Improved analysis tool, so that it only shows the relevant nodes (i.e. ones participating in paths to large functions). |
With 5 largest function source of bloat becomes pretty obvious, and is an indirectly called function 662, which is
and indeed is never called directly, but stored in the table of indirect calls as
Curiously, in case of the debug binary, the 5 largest functions are reachable in way saner manner |
Closing issue of investigation because this and other points of bloat have been identified since. Feel free to re-open if we want to use this as a tracking issue, but seems stale to me |
As reported by @willemneal some contracts when implemented in Rust are an order of magnitude larger than equivalent contracts implemented in AssemblyScript. We need to get these contracts and debug where the size bloat comes from. The first thing is however, to get an example of such contract. @nearmax have not observed such discrepancy himself.
Assigning to @willemneal to provide an example of an order of magnitude discrepancy. Also assigning to @olonho to investigate the source of the size bloat.
The text was updated successfully, but these errors were encountered: