wasm-tools: `wasmparser`: 15-30% performance regressions from v228 -> v229

I just finished updating Wasmi to the new wasm-tools v229 coming from v228.

  • Roughly 15% performance regressions across the board.
  • Up to 30% performance regressions when Wasmi translation was lazy and thus wasmparser parsing and validation made up a larger chunk of the work. So that’s probably the real regression in wasmparser.

Wasmi PR: https://github.com/wasmi-labs/wasmi/pull/1501

Benchmarking before and after revealed the following performance regressions: Image

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 22 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I can replicate this in-repo with cargo bench -p wasmparser -- parse/tests ; let me try to produce a flamegraph and take a look asap (but please don’t let me stop anybody else).

Hm ok I’m a bit surprised then, in pure validation cases in this repository nothing comes close to the 30% regression you’re seeing in lazy-translation/checked. Everything here is in the ~5-10% range for parsing+validation. Could you double-check the API-wise usage of wasmparser? Maybe an old idiom which worked isn’t the best way to do it any more? Unsure though…

I suppose if one applies all those optimizations to wasmparser’s parser then it would no longer be spec compliant?

Yes and no. This was added to validate the distinction between assert_{malformed,invalid} the spec test suite. The validator can still catch truly invalid wasms and it’s a question of whether invalid wasms (and checks) are checked during parsing instead. By using a simple depth counter it leans more heavily on validation to perform more checks (but it’s already doing most of the checks already).

The non-spec-compliance aspect comes about insofar as wasmparser will parse wasms that are malformed, or technically syntactically invalid. Such invalid wasms will still be caught by the validator, however.

IMO the answer to your question, though, is “no”. A simple depth counter would still be spec-compliant. In practice it seems the main definition the spec makes is whether a module is valid or not, and if it’s not valid it only matters that it’s rejected somehow, not precisely where. Running the spec tests, however, is a bit of another matter which is where this is very much a gray area and my opinion here is not definitive nor universally held.