-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Faster (and smaller) WASM runtime builds #12786
Conversation
…or future changes, no business logic changes here
…dependencies when compiling runtime for WASM
There was a problem hiding this 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"] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Replaced with #12790 |
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:I didn't bother measuring compile times though.