Skip to content

avm2: Speed up some native calls #20328

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

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from

Conversation

Lord-McSweeney
Copy link
Collaborator

@Lord-McSweeney Lord-McSweeney commented May 2, 2025

Depends on #20257

This allows us to optimize some calls to native functions when

  1. the function has a [Ruffle(FastCall)] annotation,
  2. the arguments are of the correct count and type, and
  3. the class of the value the function is being called on is final.

For example, Math.abs runs more than twice as fast with this PR as it does on current master. From my testing, in most SWFs, 5-20% of calls that would be CallMethod are now CallNative.

TODO:

  • Record box2d optimization stats
  • Add documentation on FastCall to the globals README
  • Use a HashSet for the FastCall methods...?

Lord-McSweeney added 30 commits May 1, 2025 18:53
Lord-McSweeney added 19 commits May 1, 2025 18:53
- `Vector$object`'s `push` and `shift` should return `*`, not `Object`
- `DisplayObjectContainer`'s `setChildIndex` returns `void`
GetProperty and CallProperty optimization logic have been moved to their own methods
Added to methods on Class, Function, Namespace, QName, String, Vector, XML
and XMLList, Graphics, SoundTransform, as well as some toplevel functions and
`getTimer`.
@Lord-McSweeney Lord-McSweeney added A-avm2 Area: AVM2 (ActionScript 3) T-perf Type: Performance Improvements labels May 2, 2025
@moulins
Copy link
Contributor

moulins commented May 2, 2025

Use a HashSet for the FastCall methods...?

An alternative (maybe simpler to implement?) could be to sort the static array, and use binary_search for O(log n) lookups.

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) newsworthy T-perf Type: Performance Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants