kaivol opened PR #9892 from kaivol:optimize-component-model-fp-performance
to bytecodealliance:main
:
Added overrides for
Lower::store_list
andLift::load_list
for floating point numbers to reduce overhead when passing or returninglist<f32>
andlist<f64>
to/from components.I based this on the respective implementation for integers.
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
dicej assigned dicej to PR #9892.
dicej submitted PR review:
Thanks for this! Looks reasonable to me overall; see my comments inline regarding the details.
dicej created PR review comment:
Again, these comments should be updated to discuss floating point types rather than integer types.
dicej created PR review comment:
This paragraph (and the code that follows) refers to
$integer
, but we really care about$float
, right? We should rewrite this to talk about floating point numbers instead of integers, e.g. "allu8
patterns are valid$float
patterns since$float
is a IEEE 754 floating point type."
dicej created PR review comment:
let (before, middle, end) = unsafe { dst.align_to_mut::<$float>() };
Presumably the alignment of e.g.
f32
andu32
should be the same, but we might as well be precise here (and in similar code below).
Thanks for the review!
I'm a bit busy at the moment but I'll look into it when i find some time.
kaivol submitted PR review.
kaivol created PR review comment:
The reason I used integer types and
align_to[_mut]::<$integer>
was to handle endianness correctly.
I felt like usingalign_to[_mut]::<$float>
and thereby transmuting the component's memory to$float
is incorrect, because (in my understanding)$float
represents floating point numbers in native endianness, whiledst
is a slice of floating point numbers with little-endian byte-order.Therefore, I thought using
$float
for floating point numbers with different endianess would also cause confusion, in particular when converting endianess.I also considered using only accordingly aligned bytes (e.g.
[u8; 4]
) for the memory of the component, but I was unsure if that would enable the same optimizations.
Is there any easy (built-in) way to benchmark Wasmtime in specific scenarios?Let me know what you think.
dicej submitted PR review.
dicej created PR review comment:
Good point; I hadn't considered what
align_to_mut
was actually doing. I agree we should leave it as you have it.Is there any easy (built-in) way to benchmark Wasmtime in specific scenarios?
You can look under the
benches
directory in this repo to see if the scenario you're interested in is already covered; if not, you'd need to add a new benchmark to that suite.
kaivol updated PR #9892 (assigned to dicej).
kaivol updated PR #9892 (assigned to dicej).
I modified the code to work with byte slices (
[u8]
) when referring to the component's memory. I think this is the best way to show which variables are host and which are component memory.I also got rid of the
unsafe
blocks, without compromising on performance (at least in my experiments).Let me know if the code looks good, and if further comments would help clarify it.
kaivol has marked PR #9892 as ready for review.
kaivol requested fitzgen for a review on PR #9892.
kaivol requested wasmtime-core-reviewers for a review on PR #9892.
dicej submitted PR review:
Thanks!
dicej submitted PR review.
dicej created PR review comment:
use core::iter;
That should fix https://github.com/bytecodealliance/wasmtime/actions/runs/14112166505/job/39533533593
kaivol updated PR #9892 (assigned to dicej).
One last thing to make CI happy (I hope): please run
cargo fmt
and push the result.
kaivol updated PR #9892 (assigned to dicej).
dicej merged PR #9892.
Last updated: Apr 18 2025 at 01:31 UTC