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

Optimize register preservation finalization #808

Open
Robbepop opened this issue Nov 25, 2023 · 0 comments
Open

Optimize register preservation finalization #808

Robbepop opened this issue Nov 25, 2023 · 0 comments
Labels
optimization An performance optimization issue. register-machine A work item for the register-machine engine.

Comments

@Robbepop
Copy link
Collaborator

Robbepop commented Nov 25, 2023

In the new wasmi register-machine translation we have to preserve values of local.get x registers if they are on the stack while an incoming local.set x or local.tee x overwrites the value of local x. In order to preserve the value of the local x we have to perform a register preservation which allocates a register at the highest index in descending order.

When translation of wasmi IR is finalized we then have to offset all those preservation register indices by the difference between the maximum non-preserved register index and the minimum preserved register index. Conservatively this operation needs to iterate over all generated wasmi IR instructions and for each check all their registers and potentially offset them if they are a preservation register. This might inspect tons of wasmi IR instructions that are not having any preservation registers.

This is very costly!

Current Solution and Proposal

In order to offset the costs a bit we currently check at which instruction index we first see a register preservation if any and only start from there which can reduce the amount of iteration by a bit. However, a much better improvement was to only ever touch those instruction that actually need to be adjusted.

This information can probably be inferred because we know whenever the stack pops off such a preserved register during translation. We could notify the register preservation finalization routine that this event occurred to track down the instructions that actually are required to be adjusted.

Difficulties

@Robbepop Robbepop added optimization An performance optimization issue. register-machine A work item for the register-machine engine. labels Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization An performance optimization issue. register-machine A work item for the register-machine engine.
Projects
None yet
Development

No branches or pull requests

1 participant