wasm2c: Optimize force_read perf and allow embedder to configure policy - #2808
Open
shravanrn wants to merge 1 commit into
Open
wasm2c: Optimize force_read perf and allow embedder to configure policy#2808shravanrn wants to merge 1 commit into
shravanrn wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
wasm2c's
FORCE_READ_*macros allow spec compliance when using guard pages by preventing elimination of potentially trapping loads, but introduces several low-level performance issues in the generated code. One example is that it prevents load followed by a modification to be prevented from being combined into a “load with modification”.Thisoccurs in one the libraries sandboxed by Firefox. The library loads a byte and extends it to 32-bits before processing it --- all in tight loop.
Since wasm2c's load byte corresponds to the following code
the generated assembly first performs a load with 32-bit load shifted to a byte, sends the byte result to the asm block, and then performs a widening. However a faster option here, is to just read the byte whie sign extending it, and then consume the sign extended result. This only requires moving the last cast prior to the asm. This simple change speeds up this library by 3%. Separately, this PR also allows the embedder to disable force_reads (this is off by default, since it is non conforming), and speeds up the same benchmark by around 5%.