ruffle icon indicating copy to clipboard operation
ruffle copied to clipboard

avm2: Optimize `findpropstrict`, `findproperty`, and `getlex`

Open Lord-McSweeney opened this issue 1 year ago • 0 comments

Also propagate types from getslot, getglobalscope, and getglobalslot.

A single getlex QName(PackageNamespace(""), "Math") executes about 2.5x faster with this PR.

New stats for box2d:

FindPropStrict -> GetScriptGlobals : 45.16%
FindPropStrict -> GetOuterScope : 7.87%
FindPropStrict -> GetScopeObject : 1.69%

FindProperty -> GetOuterScope : 2.83%
FindProperty -> GetScopeObject : 5.66%

InitProperty -> SetSlot : 38.15%
InitProperty -> SetSlotNoCoerce : 37.87%

SetProperty -> SetSlot : 15.03%
SetProperty -> SetSlotNoCoerce : 30.42%
SetProperty -> CallMethod : 1.57%

GetProperty -> GetSlot : 59.69%
GetProperty -> CallMethod : 0.34%

CallProperty -> CallMethod : 31.45%

CallPropVoid -> CallMethod : 61.74%

Coerce -> Nop : 46.95%

CoerceD -> Nop : 78.36%

CoerceB -> Nop : 8.11%

CoerceU -> Nop: 32.46%

CoerceI -> Nop : 2%

ReturnValue -> ReturnValueNoCoerce : 65.14%

(note: getproperty probably went down in percentage because we now split getlex into findpropstrict and getproperty, and the getproperty doesn't always optimize to a getslot- so the percentage looks like it went down, even though the getlex is faster)

Overall any optimization improvements other than the early scope resolution are tiny. Stockfish seems to start a little faster.

TODO:

  • [x] Handle lazy multiname passed to findproperty/findpropstrict
  • [x] Appease clippy

Lord-McSweeney avatar May 10 '24 02:05 Lord-McSweeney