Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Faster (and smaller) WASM runtime builds #12786

Closed
wants to merge 2 commits into from

Conversation

nazar-pc
Copy link
Contributor

@nazar-pc nazar-pc commented Nov 26, 2022

This tackles underlying issue from #12671 (partially) from a different angle by simply not compiling any dependencies in substrate-wasm-builder when compiling WASM version of the crate in the first place.

It is a bit awkward that WasmBuilder is copy-pasted and not implementing any shared trait with regular one, but I decided it might be acceptable for now.

What this means is that runtime is build faster and smaller.

target/debug/wbuild/node-template-runtime/target size:

  • before ~1.5G
  • after ~0.6G

I didn't bother measuring compile times though.

…or future changes, no business logic changes here
…dependencies when compiling runtime for WASM
@nazar-pc nazar-pc requested a review from koute as a code owner November 26, 2022 22:55
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Great idea! But can be improved.


[features]
default = ["std"]
Copy link
Member

Choose a reason for hiding this comment

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

Good idea, but way too complicated. Just adding target dependencies with not(target_arch = "wasm32") should do it.
Then we also don't need to enable or disable any features.

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that initially, the problem is that substrate-wasm-builder itself is never compiled for wasm32 architecture, it is always compiled to native machine code. The cleanest way to work around that that I found was to add an std feature.

I was hoping there is a way to distinguish host from target, but apparently not in this context.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, but you should be able to import wasm-builder conditionally in your downstream project based on the target_arch? Achieving the same without requiring any upstream changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost, provide_dummy_wasm_binary_if_not_exist is still necessary for WASM, so I thought having it upstream in a backwards compatible way would be more convenient than reimplementing that function in every runtime.

Copy link
Member

Choose a reason for hiding this comment

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

Why is that required? The wasm binary is only imported on std builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I recall there was something when I was testing, will check again later.

@nazar-pc
Copy link
Contributor Author

Replaced with #12790

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants