-
Notifications
You must be signed in to change notification settings - Fork 245
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
wasmparser
: optimize type section valiadation by specializing over Wasm feature subset
#1906
wasmparser
: optimize type section valiadation by specializing over Wasm feature subset
#1906
Conversation
wasmparser
: Add specialized type section validation for Wasm feature subset
wasmparser
: Add specialized type section validation for Wasm feature subsetwasmparser
: optimize type section valiadation by specializing over Wasm feature subset
I also ran the
I have looked through a bunch of the reported errors and they seem to be expected from the turning-off of features. However, it would certainly be nicer if we had an automated way of testing this fast-validation path. |
I think is possible to simplify Wasm feature checking by making
This way it was not possible to have Wasm features sets that do not make much sense. Or are there problems that I have overlooked? 🤔 |
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.
Thanks! Do you think it would be possible to optimize the processing of types in-place though rather than conditionally gating on features? From a high-level I don't think we have any other logic where we significantly differ on features for what path to take at runtime (except to return an error). I'm worried that this will become a relatively poorly tested path due to not being the default and being relatively nontrivial. I haven't dug in much though to try to understand what the slow parts are here though so it may not be possible.
Otherwise for feature dependencies I'm not sure how to best manage that. We already primarily use method accessors for features rather than .contains(WasmFeatures::FEATURE)
so it might not be too hard to update those accessors to automatically test for a set of bits rather than just a single bit.
I agree that this solution is not ideal. To me this is just a temporary solution to make An idea for an inline solution: Perform the light-weight validation introduced in this PR until a type is encountered that strictly requires all the type canonicalization, sub-type checking etc. Then, perform all those steps for all the types seen so far and continue with this more elaborate approach. @alexcrichton Do you think this is feasible? Slow parts of type section validation are:
All of those are prevented in this PR for the selected set of features. I would really love to use upstream |
I have experimented with an implemented for the idea presented in this comment. However, problems arised quickly due to certain invariants of other structures in the validator's greater scheme. For example resetting the All in all, I think a proper, more elegant approach would take a lot of more work and consideration. This PR implements a very fast type section validation at nearly no runtime cost (one bit-flags check). The feature gated allow list should be fairly maintainble since development of new features won't casually break the type validator and old features won't change their semantics. Once we figure out a more elegant and inline approach for fast type section validation, this solution can easily be replaced since it is neatly isolated and contained in a single spot. |
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.
Thanks for investigating! I think that's a reasonable approach myself and the benefits seem worth the theoretical risk here, so I'm happy to land this. It's also not like this has zero testing, the "feature frobbing" done in Wasmtime and wasm-tools fuzzing should still cover this case.
Closes #1701.
cc @alexcrichton : Are there any other Wasm proposals that might conflict?
This implements a lightweight type section validation for a subset of Wasm proposals.
Benchmarks
I compared
main
against PR and changed the usedWasmFeatures
set for both: