Optimize ValType parsing in wast
#2365
Merged
+145
−152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fuzzing timed out recently with a test case and some profiling showed that parsing types was an alarmingly large amount of the profile. This commit optimizes the parsing of
ValTypeby avoiding the use ofLookahead1for example and the general style of recursive-descent parsing. Recursive descent parsing performs well when there's not a big branch of what to parse next, but in the case ofValTypethere's a lot of possible branches which meant that the prior idioms ended up generating a pretty slow parser.With this commit the fuzz-generated test case parses 3x faster, dropping from ~1s to 300ms. Still not great, but hopefully fast enough for the fuzzer.