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

avm2: Optimizer improvements #15105

Merged

Conversation

Lord-McSweeney
Copy link
Collaborator

@Lord-McSweeney Lord-McSweeney commented Feb 3, 2024

Based off @adrian17's abstract-optimizer branch.

Testing on the Box2D demo SWF shows that:
55% of GetProperty calls are converted to GetSlot or CallMethod calls
36% of SetProperty calls are converted to SetSlot calls
74% of InitProperty calls are converted to SetSlot calls
25% of CallProperty calls are converted to CallMethod calls

Testing on Sniper Team shows that PropertyMap::get_for_multiname is pushed down significantly. However Activation::run_actions is still too high for it to make a noticeable difference.

Fixes #15227
Fixes #15273
Fixes #15309

TODO:

  • Constant pooling fixes For later
  • Optimize CallProperty to CallMethod
  • Also support setters for SetProperty and InitProperty For later
  • Remove Nops (requires recalculating branch and jump targets) For later
  • Resolve parameter types ([WIP] avm2: Store resolved function param types #11954)
  • Maintain scope stack, at least topmost level
    • Use it for determining type returned by findproperty/findpropstrict For later
  • Implement more ops For later

@Lord-McSweeney Lord-McSweeney added A-avm2 Area: AVM2 (ActionScript 3) T-perf Type: Performance Improvements labels Feb 3, 2024
@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from a74dcc4 to ef23851 Compare February 3, 2024 23:19
@Lord-McSweeney Lord-McSweeney marked this pull request as draft February 3, 2024 23:21
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
stack.pop();
stack.push_int();
}
_ => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned on discord, I think we should just have all of these checked in one go - otherwise this can't be used for verification, and can randomly inhibit optimizations.

@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from bbcc1f4 to 464274a Compare February 4, 2024 04:00
core/src/avm2/verify.rs Outdated Show resolved Hide resolved
@@ -2243,23 +2249,23 @@ impl<'a, 'gc> Activation<'a, 'gc> {
let value2 = self.pop_stack().coerce_to_i32(self)?;
let value1 = self.pop_stack().coerce_to_i32(self)?;

self.push_stack(value1.wrapping_mul(value2));
self.push_raw(value1.wrapping_mul(value2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could also be applied to some more ops: add, subtract, swap, astype, astypelate? For the last three, since other ops guarantee that stack never has PrimitiveObject, then they can also never encounter a PrimitiveObject.

@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from deaf921 to 06cbbe4 Compare February 19, 2024 20:50
@Lord-McSweeney Lord-McSweeney marked this pull request as ready for review February 19, 2024 22:07
@torokati44 torokati44 force-pushed the avm2-abstract-optimizer branch from 7787587 to 5af94c9 Compare February 21, 2024 10:07
@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from 5af94c9 to 6bdca88 Compare February 24, 2024 20:43
@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from 6bdca88 to d2971e8 Compare February 24, 2024 20:44
core/src/avm2/optimize.rs Outdated Show resolved Hide resolved
core/src/avm2/optimize.rs Outdated Show resolved Hide resolved
core/src/avm2/optimize.rs Show resolved Hide resolved
core/src/avm2/optimize.rs Show resolved Hide resolved
core/src/avm2/optimize.rs Show resolved Hide resolved
core/src/avm2/optimize.rs Outdated Show resolved Hide resolved
}

fn popn(&mut self, count: u32) {
for _ in 0..count {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if something like self.0.truncate(self.0.len() - count) would be more efficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to be too worried about performance here

core/src/avm2/optimize.rs Outdated Show resolved Hide resolved
@Lord-McSweeney Lord-McSweeney force-pushed the avm2-abstract-optimizer branch from 890c690 to dce4238 Compare February 25, 2024 18:59
@Lord-McSweeney Lord-McSweeney merged commit 11d5a8f into ruffle-rs:master Feb 26, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-avm2 Area: AVM2 (ActionScript 3) T-perf Type: Performance Improvements
Projects
Status: No status
4 participants