About function call inlining


About function call inlining

~~~~~~~~~~~~~~~~~~ Dears, method inlining anyone expects.

I’m again doing a poor, but motivation post for future method inlining support. I said bad things for the Flash platform in this community, all due to performance and old-lity. I know Flash Professional since I was 12 (2014), and I’m experienced enough with ActionScript.

For release cases, I can confirm MXMLC-generated ABCs don’t have inlineable function-calls inlined. I won’t tell how I did prove it; that’s obvious.

But what if we had a modern tool for inlining AS3 methods? Also using Flash libraries such as…:

The reality behind inlining.

  • Any plans to improve AS3 performance? (Feb 26, 2015 3:09 AM) One flashdictionary’s point: ActionScript Inline feature was never completed. As a result, the major ActionScript frameworks such as Starling, Away3D are not taking advantage of the Inline feature.

  • Miscellaneous optimizations The inline part ― Inline code, when possible, to reduce the number of function calls in your code. ― recommends you to manually inline code. More context: Calling functions can be expensive. Try to reduce the number of function calls by moving code inline. Moving code inline is a good way to optimize for pure performance. However, keep in mind that inline code can make your code harder to reuse and can increase the size of your SWF file. Some function calls, such the Math class methods, are easily to move inline. […] These tips might be old (I don’t know), but if Adobe posted it, it means AVM2 might do nothing about method inlining when executing ABC (that would make program initialiastion slower).


I found Joa Ebbert’s Apparat tools in a famous SO question. Sadly, though, Apparat only inlines static methods and requires extending a Inline class or using a [Macro] meta-data (something like that).


The inlining method optimisation is hard for pure ECMAScript dev’s. Always possible, but yk: boring.

For AS3 dev’s it’s easier: fixed properties and mostly readonly function definitions. Namespace quals (with use namespaces) are easily detected.

I made a bit of a readme for a future solution. Share me your thoughts.


Ohmm, not 2 forget: Adobe is lazy 8 optimising. They commit failures 8 this point :frowning: . Unfortunately I won’t be able to build my Bitzier drawing editor 4 creating my anime-like series, kkk.


Except ASC2 support function inlining since 2012

see Adobe ActionScript Compiler 2.0 Release Notes (PDF)

and ActionScript Compiler 2.0 Backward Compatibility

use the metadata [Inline] and the compiler option -inline

for inlining to work you need to follow those rules

  • The function is final, static or the containing scope is file or package
    Compiler Error Message:

    The function myFunction could not be inlined, as only functions marked as final, static or global functions can be inlined.

  • The function does not contain any activations

  • The function does not contain any try or with statements

  • The function does not contain any function closures

    // global function
    public function test1():String
        return "hello world";
    public class Test
        private var _abc:uint = 0;
        private static var _def:uint = 1;

        // final method
        public final function abc1():uint
            return _abc;

        // static method
        public static function def2():uint
            return _def;

from an install of the AIR SDK
go to the bin/ folder

$ ./mxmlc -help list

Adobe ActionScript Compiler (mxmlc)
Version 2.0.0 build 354200
Copyright 2004-2012 Adobe Systems Incorporated. All rights reserved.

-compiler.actionscript-file-encoding <string>
-compiler.context-root <context-path>
-compiler.external-library-path [path-element] [...]
-compiler.fonts.local-font-paths [path-element] [...]
-compiler.fonts.local-fonts-snapshot <string>
-compiler.fonts.max-cached-fonts <string>
-compiler.fonts.max-glyphs-per-face <string>
-compiler.include-libraries [library] [...]
-compiler.library-path [path-element] [...]
-compiler.locale [locale-element] [...]
-compiler.minimum-supported-version <string>
-compiler.mxml.compatibility-version <version>
-compiler.mxml.minimum-supported-version <string>
-compiler.namespaces.namespace [uri] [manifest] [...]
-compiler.preloader <string>
-compiler.services <filename>
-compiler.source-path [path-element] [...]
-compiler.theme [filename] [...]
-error-problems [class] [...]
-help [keyword] [...]
-ignore-problems [class] [...]
-include-resource-bundles [bundle] [...]
-load-config <filename>
-metadata.contributor <name>
-metadata.creator <name>
-metadata.date <text>
-metadata.description <text>
-metadata.language <code>
-metadata.localized-description <text> <lang>
-metadata.localized-title <title> <lang>
-metadata.publisher <name>
-metadata.title <text>
-output <filename>
-runtime-shared-libraries [url] [...]
-runtime-shared-library-path [path-element] [rsl-url] [policy-file-url] [rsl-url] [policy-file-url]
-swf-version <int>
-target-player <version>
-tools-locale <string>
-warning-problems [class] [...]

$ ./mxmlc -help advanced optimize

Adobe ActionScript Compiler (mxmlc)
Version 2.0.0 build 354200
Copyright 2004-2012 Adobe Systems Incorporated. All rights reserved.

    alias -optimize
    Enable post-link SWF optimization

$ ./mxmlc -help advanced inline

Adobe ActionScript Compiler (mxmlc)
Version 2.0.0 build 354200
Copyright 2004-2012 Adobe Systems Incorporated. All rights reserved.

    alias -inline
    turn on the inlining of functions (advanced)

For optimizing ABC/SWF bytecode, again ASC2 since AIR 3.6 supports the avm2.intrinsics.memory package

see Faster ByteArray Operations with ASC2

The ActionScript bytecode generated by FlasCC delivers higher performance than the bytecode generated by the ActionScript compiler. Apart from the usage of better data types and instructions, FlasCC has the advantage of using domain memory which results in faster read/write access of the memory buffer. Flash and AIR Runtimes already support the special memory opcodes needed to use domain memory. The unavailability of a toolchain (Flash Builder, Flash Pro, AIR SDK) did not make it possible to use domain memory for creating .swf files. Beginning AIR 3.6, the ActionScript compiler (ASC2) also generates fast memory opcodes directly from the AS3 code (previously available only through FlasCC).

Making ByteArray faster
An ASC 2.0 Domain Memory Opcodes Primer
Domain Memory Opcode Performance: Reading and Writing

Most of those things already mentioned in Memory and Performance.

Now for commenting a bit

there are many things you’re pointing at that are particularly unfair or outdated

I get it that some dev can get confused with the ActionScript Compiler 2.0 Backward Compatibility

it can happen on some tiny use cases that some bugs exists

yeah sure some big popular library may not use this or that

but in the end those tools are there, they do works
ASC2 inlining and fast memory opcodes are perfectly valid and useable features

so please don’t use forum posts as facts because most of what you pointed at are plain wrong

if you want to inline functions in AS3 the right tool is ASC2 and the [Inline] metadata, not Apparat

eg. the right answer on StackOverflow should be the one from Sarah Northway

Adobe introduced native inline functions with the new ASC2 compiler in 2012. Use the -inline compiler argument to inline all getters and setters and any functions marked with the new [Inline] metadata. Inlined functions must meet these conditions:

Not that using Apparat was wrong at the time but there is an history in all that

  • Adobe release project Alchemy as beta/pre-release
  • people discover that Alchemy can write some specific undocumented SWF opcodes
  • Joa Ebbert release Apparat which allow to write those SWF opcodes
  • Adobe release FlasCC (official name of project Alchemy)
  • Adobe release ASC2 which allow to write those SWF opcodes

so yeah there was a relatively short period of time where Apparat was the only tool available
but it did not last forever, sadly the answer on StackOverflow does not reflect that
and so people will have a tendency to think they can only use that feature by using Apparat


@zwetan I already found that ASC 2.0 meta-data trick, but I had compiled test code using MXMLC (what I believe extends from ASC) and nothing got changed in ABC. (Also, what about calling a method from a pushed-scope this?)

And more:

  • ASC 2.0 is painful.
  • No where I had heard about the MXMLC -compiler.inline option. Adobe said nothing about that option.

Anyways, after the next time my laptop gets free, I’ll do more tests.

(Unrelated, but a AS3 dev cannot even run MXMLC in Android… There’s Java N-IDE and Dory.JS, but no MXMLC. Don’t tell me there are VMs (whose performance is poor).)

closed #5

archived #6