Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Add unchecked version of stelem_ref interpreter opcode #99829

Merged
merged 4 commits into from
May 23, 2024

Conversation

kg
Copy link
Contributor

@kg kg commented Mar 15, 2024

The generic opcode for storing reference types into arrays has to perform a full type check for the new element to make sure it's compatible with the destination array, due to array variance. In many cases however, if the element type of the array is sealed, we can theoretically skip this check and do the assignment safely in all cases. My understanding is that ryujit already does a form of this optimization, so I added a basic version of it to the mono interpreter.

The jiterpreter is also updated to exploit this opcode, because with the removal of the type-check it's now possible to inline most of the opcode into traces instead of calling a more expensive helper to do the array store. This will enable other existing jiterpreter optimizations like null check fusion to apply to stelem_ref that couldn't before.

My initial testing shows that this hits many uses of string[] during a run of System.Runtime.Tests, and according to some quick jiterpreter instrumentation the new opcode appears in some hot paths during the test run as well, so I'm hoping this will be profitable for some real-world code. (It's hard for me to measure locally.)

Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

@kg kg marked this pull request as ready for review March 18, 2024 23:42
@lewing
Copy link
Member

lewing commented May 28, 2024

@kg this looks like it might have regressed the Vector128 numbers a bit in https://radekdoulik.github.io/WasmPerformanceMeasurements

Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
…#99829)

* Introduce mint_stelem_ref_unchecked
* Inline most of stelem_ref_unchecked in jiterpreter traces
* Add more complete type check for stelem_ref_unchecked
* Correctness fix and simplification for stelem_ref_unchecked
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants