Skip to content

Conversation

@alexcrichton
Copy link
Member

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.

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.
@alexcrichton alexcrichton requested a review from a team as a code owner October 27, 2025 06:05
@alexcrichton alexcrichton requested review from abrown and removed request for a team October 27, 2025 06:05
@alexcrichton alexcrichton added this pull request to the merge queue Oct 27, 2025
Merged via the queue into bytecodealliance:main with commit c77e94d Oct 27, 2025
34 checks passed
@alexcrichton alexcrichton deleted the optimize-type-parsing branch October 27, 2025 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants