Repository navigation
wasm2c: Optimize force_read performance - #2808
Merged
Merged
Conversation
shravanrn
force-pushed
the
forcereadopt
branch
2 times, most recently
from
August 11, 2026 23:17
9d783fb to
8aa754b
Compare
shravanrn
force-pushed
the
forcereadopt
branch
from
August 16, 2026 21:58
8aa754b to
b0bc55c
Compare
Collaborator
Author
|
@sbc100 If you have a chance this is the other PR that I am really hoping to land soon as it has a large performance delta. Most of the others that I will submit shortly are much more targeted/minor optimizations. Please have a look if possible. |
sbc100
reviewed
Aug 16, 2026
Member
|
Is the PR description up-to-date? I'm not sure how the patch solves the two issues outlined? |
shravanrn
force-pushed
the
forcereadopt
branch
from
August 16, 2026 23:01
b0bc55c to
0487b22
Compare
shravanrn
force-pushed
the
forcereadopt
branch
from
August 16, 2026 23:13
0487b22 to
a4f48ed
Compare
Collaborator
Author
Sorry, my bad the second change had gotten lost at some point due to a rebase. I have pushed the updated PR now and removed the NONCONFORMING change. (No rush on this PR: the NONCONFORMING PR which I will upload shortly is more time sensitive) |
sbc100
approved these changes
Aug 17, 2026
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.It prevents load followed by a modification to be prevented from being combined into a “load with modification”. This occurs 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%.
The force_read currently uses the general purpose register "r" for force_read_float. This forces C compilers to emit an expensive float-register to int-register conversion on most architectures. The result of this is roughly an extra 7% overhead when running a sandboxed libsoundtouch which is used by Firefox to adjust the playback speed of audio files.