POC: avm2: basic peephole optimization of getproperty->getslot/callmethod #7920
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.
Given a function:
In the marked places, the
getproperty
opcode can be relatively easily resolved statically - we know the type of the variable (in case oflocal1
, it can be deduced from compiler-generatedcoerce
opcodes), so we can calculate vtable lookup in advance and replace the opcode by a correspondinggetslot
orcallmethod
(if it's a getter). This basic version also doesn't require any dataflow analysis or building a control flow graph.This PR implements such an optimization.
This is a very minimal proof of concept with very rough edges (you can see more extensive analysis in the long comment in
method.rs
), but it's good enough to eliminate 80% ofgetproperty
opcode invocations in the box2d demo SWF.That said, the runtime benefit is much smaller than I expected, so I think this kind of thing should wait until other, more important optimizations are performed.
Due to that, I'm gonna make this PR and immediately close it, just to keep it for posterity.