-
Notifications
You must be signed in to change notification settings - Fork 263
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.
…ng over Wasm feature subset (bytecodealliance#1906)" This reverts commit 9cebc6a.
This commit fixes an issue from bytecodealliance#1906 which is preventing the upgrade of wasm-tools in Wasmtime. That commit implemented a fast path by skipping a function and reimplementing parts of it internally, but that then caused Wasmtime to panic when other data structures weren't filled out. The intention was that the user-facing interface doesn't change depending on features, so this is an attempt at fixing the mistake in that commit. The fix here is to remove the fast path added and restructure it differently. Instead now the fast and normal paths have much less divergence which should prevent this issue from re-surfacing. This is 15% slower than `main` but it doesn't have the same bug as `main` so for now that may be the best that can be done.
* Add a benchmark for validating with older features Benchmark the "fast path" in type interning. * Reimplement fast-path validation of MVP types This commit fixes an issue from #1906 which is preventing the upgrade of wasm-tools in Wasmtime. That commit implemented a fast path by skipping a function and reimplementing parts of it internally, but that then caused Wasmtime to panic when other data structures weren't filled out. The intention was that the user-facing interface doesn't change depending on features, so this is an attempt at fixing the mistake in that commit. The fix here is to remove the fast path added and restructure it differently. Instead now the fast and normal paths have much less divergence which should prevent this issue from re-surfacing. This is 15% slower than `main` but it doesn't have the same bug as `main` so for now that may be the best that can be done. * Fix dead code warning
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: