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

[WIP] Size optimisations #32

Closed
wants to merge 2 commits into from
Closed

[WIP] Size optimisations #32

wants to merge 2 commits into from

Conversation

axic
Copy link
Member

@axic axic commented Dec 21, 2018

Use wasm-snip and wasm-gc

Cargo.toml Outdated
@@ -14,3 +14,5 @@ members = [

[profile.release]
lto = true
opt-level = 's'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're doing precompiles, size should not matter as much since my understanding is these system contracts will be stored locally. Gas costs are fixed for execution, might as well optimize for performance.

Copy link
Member

@jakelang jakelang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a step to install wasm-snip and wasm-gc

@axic
Copy link
Member Author

axic commented Dec 21, 2018

This was my work in progress branch for testing various settings and compilers. Not meant to be merged anytime soon.

@jakelang jakelang dismissed their stale review December 21, 2018 19:06

k, will leave this be.

@axic
Copy link
Member Author

axic commented Dec 22, 2018

The identity precompile:

 Shallow Bytes │ Shallow % │ Item
───────────────┼───────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
         27509 ┊    28.29% ┊ custom section '.debug_str'
         26358 ┊    27.10% ┊ custom section '.debug_info'
         16595 ┊    17.06% ┊ custom section '.debug_pubtypes'
          9879 ┊    10.16% ┊ custom section '.debug_pubnames'
          7470 ┊     7.68% ┊ custom section '.debug_line'
          3458 ┊     3.56% ┊ dlmalloc::dlmalloc::Dlmalloc::malloc::h5891d2855e0d9ebe
          1824 ┊     1.88% ┊ custom section '.debug_ranges'
          1478 ┊     1.52% ┊ custom section '.debug_abbrev'
           829 ┊     0.85% ┊ "function names" subsection
           473 ┊     0.49% ┊ data[0]
           339 ┊     0.35% ┊ dlmalloc::dlmalloc::Dlmalloc::unlink_large_chunk::hf603e4746ddb82d9
           326 ┊     0.34% ┊ dlmalloc::dlmalloc::Dlmalloc::insert_large_chunk::he0b6e9bfcf411f56
           104 ┊     0.11% ┊ data[1]
            82 ┊     0.08% ┊ custom section '.debug_loc'
            73 ┊     0.08% ┊ ewasm_api::unsafe_calldata_copy::h5f6de487f23eefd0
            72 ┊     0.07% ┊ data[2]
            52 ┊     0.05% ┊ main
            27 ┊     0.03% ┊ import ethereum::getCallDataSize
            24 ┊     0.02% ┊ import ethereum::callDataCopy
            18 ┊     0.02% ┊ import ethereum::useGas
            18 ┊     0.02% ┊ import ethereum::finish
            17 ┊     0.02% ┊ custom section '.debug_macinfo'
            13 ┊     0.01% ┊ _$LT$T$u20$as$u20$core..any..Any$GT$::get_type_id::h70a50119ef9c01da
            11 ┊     0.01% ┊ alloc::raw_vec::capacity_overflow::h0432b49d9a8429de
            10 ┊     0.01% ┊ ewasm_api::finish_data::h5496bba85d7111e5
             9 ┊     0.01% ┊ export "memory"
             8 ┊     0.01% ┊ global[0]
             8 ┊     0.01% ┊ global[1]
             8 ┊     0.01% ┊ global[2]
             8 ┊     0.01% ┊ core::panicking::panic::h158c6e3285d6c3fb
             7 ┊     0.01% ┊ export "main"
             7 ┊     0.01% ┊ elem[0]
             7 ┊     0.01% ┊ ewasm_api::consume_gas::haca660fedcbabea6
             6 ┊     0.01% ┊ type[1]
             6 ┊     0.01% ┊ _$LT$alloc..raw_vec..RawVec$LT$T$C$$u20$A$GT$$GT$::allocate_in::_$u7b$$u7b$closure$u7d$$u7d$::h038a550a99ce6b55 (.llvm.3105678208255263009)
             5 ┊     0.01% ┊ type[3]
             5 ┊     0.01% ┊ type[5]
             5 ┊     0.01% ┊ type[7]
             5 ┊     0.01% ┊ ewasm_api::calldata_size::hba1f916f3ba69165
             4 ┊     0.00% ┊ type[0]
             4 ┊     0.00% ┊ type[2]
             4 ┊     0.00% ┊ type[6]
             4 ┊     0.00% ┊ table[0]
             3 ┊     0.00% ┊ type[4]
             3 ┊     0.00% ┊ core::ptr::drop_in_place::h088e8834711f879a (.694)
             2 ┊     0.00% ┊ memory[0]
             1 ┊     0.00% ┊ func[0]
             1 ┊     0.00% ┊ func[1]
             1 ┊     0.00% ┊ func[2]
             1 ┊     0.00% ┊ func[3]
             1 ┊     0.00% ┊ func[4]
             1 ┊     0.00% ┊ func[5]
             1 ┊     0.00% ┊ func[6]
             1 ┊     0.00% ┊ func[7]
             1 ┊     0.00% ┊ func[8]
             1 ┊     0.00% ┊ func[9]
             1 ┊     0.00% ┊ func[10]
             1 ┊     0.00% ┊ func[11]
             1 ┊     0.00% ┊ func[12]

Basically snip/gc cannot remove those debugging sections.

The identity is 97250 bytes long. Out of that debug sections sum to 91212 bytes and the names section (only needed for debugging) is 829 bytes. 94.65% is debugging information. Properly stripping it will result in 5209 bytes for the identity. Still quite big, but not a monster as it is now.

Stripping these sections is where wasmx/wasm-chisel#48 will be useful.

50% of the remaining code is dlmalloc, which we can get rid of my using our own allocator.

@axic
Copy link
Member Author

axic commented Apr 26, 2019

This is mostly obsolete now.

@axic axic closed this Apr 26, 2019
@axic axic deleted the size-optimisations branch April 26, 2019 12:52
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

Successfully merging this pull request may close these issues.

2 participants