Optimize `ValType` parsing in `wast` by alexcrichton · Pull Request #2365 · bytecodealliance/wasm-tools

@alexcrichton

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 `ValType` by avoiding the use of
`Lookahead1` for 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 of `ValType` there'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.