-
Notifications
You must be signed in to change notification settings - Fork 289
Optimize OperatorsReader
control stack
#2241
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
Conversation
Thanks! I'm personally a bit hesitant to go the route of micro optimizations like this just yet mostly insofar that I don't believe this composes with #2228. If doing a pure parse in isolation then this complements #2228 but if doing a parse with a validator this won't be used (and that's the main case that I'd like to optimize for) |
@alexcrichton thanks for your reply. It seems that I have overlooked the fact that #2228 also provides a solution for init-expressions. When I have reviewed #2228 some days ago I didn't notice that. Though, this PR might still have positive impacts on performance since it inlines the top-most block and simplifies some users that do not care about the initialization of the operators reader - though in all honesty for those users performance might not be important. Due to the results in #2180 (comment) where boths PRs showed improvements in different test cases I was under the impression that both PRs compose well with each other. |
To be clear I agree this PR improves performance, but what it's improving, assuming #2228 is merged, is parse-without-validation performance. The validator won't use this optimization at all because it has its own stack of frames which doesn't have the top frame cached in the structure. Put another way the gains on |
I get that those PRs focus on different areas. Though, to Wasmi, parse-without-validation performance matters too, since performance sensitive users can skip validation with this API which is used by some users when they can assert otherwise that they are operating with pre-validated Wasm binaries: https://docs.rs/wasmi/latest/wasmi/struct.Module.html#method.new_unchecked I can understand if you do not want to go into the direction of this PR. Maybe a different solution is needed. |
Ah ok, that makes sense. With the |
Sure, I will rebase on top of #2228 and see how the combined changes impacts benchmarks. |
@Robbepop, I didn't realize Wasmi had a I took a look at how Wasmi is using wasmparser, and I think it may be possible for Wasmi to avoid ever creating a |
Thanks! For Wasmi the
Yes you are right about how or where Wasmi can make use of the new |
@keithw I checked today. Is it possible to change the signature of |
Sure, no objection from me. |
097c734
to
9dc19b5
Compare
@alexcrichton I rebased this PR on Benchmarks show that validation benchmarks are not affected but parse benchmarks are, as expected: |
9dc19b5
to
cd6b84b
Compare
I resolved conflicts and rebased on |
Alternative or addition to #2228.
The
OperatorsReader
control stack that has been introduced in #2134 always contains at least oneframe
which causes this common path to always require heap allocations. Since theOperatorsReader
type is used pervasively during parsing, validation and deconstructing init-expressions (or const-expressions) those heap allocations quickly sum up. Especially large Wasm modules could have hundreds or tousands of init-expressions.This PR introduces a new
ControlStack
type that optimizes this by not requiring heap allocations for just a single frame on the control stack.Inline annotations have been added where necessary to improve performance. Every such annotation has been benchmarked.
Benchmarks comparing
main
with this PR:cc @alexcrichton @keithw