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

POC: avm2: basic peephole optimization of getproperty->getslot/callmethod #7920

Closed

Conversation

adrian17
Copy link
Collaborator

@adrian17 adrian17 commented Sep 8, 2022

Given a function:

class C {
    public function f(arg1: SomeClass, arg2) {
          trace(this.stuff); // <---
          trace(arg1.stuff); // <---
          trace(arg2.stuff);
          var local1: SomeClass = (...);
          var local2 = (...);
          trace(local1.stuff); // <---
          trace(local1.stuff.otherstuff); // <---
          trace(local2.stuff);
    }
}

In the marked places, the getproperty opcode can be relatively easily resolved statically - we know the type of the variable (in case of local1, it can be deduced from compiler-generated coerce opcodes), so we can calculate vtable lookup in advance and replace the opcode by a corresponding getslot or callmethod (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% of getproperty 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant