Fun with code (since 2006)

Introducing ASC 2.0


08.28.12 Posted in Actionscript 3 by

ASC 2.0A few minutes ago we just posted a preview on Adobe Labs of the new ActionScript Compiler (ASC 2.0) as part of the AIR 3.4/FP 11.4 SDK. You can find the complete release notes here. To fully utilize this new AIR 3.4 preview SDK, make sure you use Flash Builder 4.7 Preview also available here, which includes all this, plus things like Concurrency (ActionScript Workers) support for debugging and more.

Here are below the main improvements added to the ActionScript compiler:

  • Flash Builder 4.7 and the ASC 2.0 command-line compiler now share the same code model. This avoids duplicate representations of a program and means the IDE has an accurate representation of the language - matching the compiler.
  • A new multi-threaded architecture allows multiple files to be compiled at once, improving compilation time.
  • Better constant-folding and constant-propagation results in better performing code at runtime.
  • Reduces function overhead by removing unnecessary activation records.
  • Contains some demonstration byte-code optimizations for in-lining and dead code elimination.
  • Non-linear control flow added to AS3 through a new 'goto' keyword.
  • SWF 13 with LZMA compression is now supported.
  • A new symbol management system means Flash Builder 4.7 ActionScript workspaces that mix Flash and AIR projects should incrementally compile much faster.
  • ASC 2.0 based versions of fontswf, optimizer, swfdump and swcdepends command-line tools are available.
  • Legacy versions of asdoc and fdb command-line tools are also still included.
  • Font transcoding has been removed from [Embed] syntax. Fonts should be pre-transcoded and embedded as a SWF, which can be performed using a tool like fontswf or Flash Professional CS6.
  • Relative paths in source code ([Embed] assets, includes, etc...) resolve relatively from the including file. To specify a path relative from a source root, prefix your path with a forward slash '/'.
  • US English compiler error messages have been translated into French, Japanese, and Simplified Chinese. The locale is determined by the JVM and can be overridden using the -tools-locale configuration option.

We also added support for inlining. When the inlining feature is enabled, the compiler will attempt to inline getters, setters and any functions which are decorated with [Inline] metadata. Make sure you also add the -inline compiler argument.

A function can be inlined when the following constraints are met:

  • The function is final, static or the containing scope is file or package
  • 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
  • The function body contains less than 50 expressions

Below are some basic examples of functions which the compiler will and won't be able to inline.

package
{
    public interface IA
    {
        function get m():int;
        function f0(p:int):int
    }

    public class A implements IA
    {
        private var _m:int = 0;
        private static var _s:int = 0;

        // inlineable as final getter
        [Inline]
        final public function get m():int
        {
            return _m;
        }

        // inlineable as final setter
        [Inline]
        final public function set m(m:int):void
        {
            if (m > 0)
                _m = m;
            else
                _m = 0;
        }

        // inlineable as static getter
        [Inline]
        static public function get s():int
        {
            return _s;
        }

        // inlineable as static setter
        [Inline]
        static public function set s(s:int):void
        {
            _s = s;
        }

        // inlineable as decorated with inline metadata and final
        [Inline]
        final public function f0(p:int):int
        {
            var v:int = p + _m;
            return v;
        }

        // not inlineable as decorated with inline metadata and final, but
        // contains try stmt
        final public function f1(p:int):int
        {
            try
            {
                return p + _m;
            }
            finally
            {
                return 0;
            }
        }
    }
}

var a:A = new A();
a.m = 5; //inlined
A.s = 7; //inlined
a.f0(0); //inlined
a.f1(0); // not-inlined, as f1 contains a try stmt

var ia:IA = a;
ia.f0(0); // not-inlined as f0 access through an interface

If you want to know more about the backward compatibility for ASC 2.0, check the following link.

Please test ASC 2.0 and provide your feedback on performance or any potential bugs you may find. Thanks guys!



99 Responses to “Introducing ASC 2.0”

  1. The best way ins’t use direct registered Font Class in a SWC? Personally, I like that :)

  2. Hello Thibault, Can you give us some explanations about “goto”, I have found that it was for the Alchemy team, but what else?

    What you meant by “activation” for inline? Is it possible to have a sample of “activation” statement?

    Thanks ;-)
    Alain

  3. Thibault, We really need detailed explanations + “inline” because then I can not understand ..

    Test in Main Class:

    var result:Number = math01(12345);

    [Inline]
    final public function math01(data:Number):Number
    {
    var i:int;
    for (i = 1000000; i > 0; i– )
    {
    data = Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data)) ;
    }
    return data;
    }

    I have this warning/error and inline don’t work

    Avertissement : Définition de variable en double : i.
    var i:int;
    ^

    The same Fucntion in Satic in the other class don’t give error, but is not faster than without inline

    public class InlinedTest
    {

    [inline]
    static public function math01(data:Number):Number
    {
    var i:int;
    for (i = 1000000; i > 0; i– )
    {
    data = Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data)) ;
    }
    return data;
    }

    }

    For cons, this function placed in Main (not other class) work fine and speed increase by +/- 25-30% with [inline] directive.

    [Inline]
    final private function bar(a:Number):Number
    {
    return Math.sqrt(Math.sqrt(a * a) * Math.sqrt(a * a));
    }

    Why ?? please D.R. :)

  4. HB says:

    I’ve been thinking that would be nice to see tail recursion in AS Next as well. In the past I made a project with some big calculations that often surpassed the max number of recursions, even although it could take serious advantage of tail recursion. Rewrote it so recursion was not a problem, but recursion made it look a bit better.

    At the end I completely removed the AS code as anyway it could sometimes give timeouts, and moved all the logic to server side code.

  5. Jozef Chutka says:

    according to: Adobe ActionScript Compiler 2.0 Release Notes
    ASC 2.0 versions of the Flex ant tasks and are in ant/lib/flexTasks.jar
    Ant tasks are defined as:
    mxmlc=com.adobe.flash.compiler.ant.MXMLCTask
    compc=com.adobe.flash.compiler.ant.COMPCTask

    but if you open flexTasks.jar (available )
    mxmlc=flex.ant.MxmlcTask
    compc=flex.ant.CompcTask

    Other than that FB4.7 and its sdk seems to be real mess, why it is marked as 4.6.0 when the content is far distatnt from the one I can find in sdk download site?

  6. Kevin Newman says:

    Does the inline keyword work with AS3 Proxy class’s callProperty? That would be pretty sweet. :-)

  7. HB says:

    Could we get some examples of functions that contain 50 expressions? Which do you consider an expression?

    Also, I guess that if a function marked with [Inline] calls another inlined function, the number of expressions from the second sum to the number of the first, doesn’t it?

    Was thinking of using this for a couple of functions, but I think that I surpass this limit.

  8. Peter Farland says:

    @Jozef, Note that overlaying the preview “AIR 3.4 SDK with ASC 2.0″ on top of a legacy Flex SDK is not supported.

    ASC 2.0 replaces the old compiler. It is for pure-AS3 development and cannot be mixed with the legacy Flex SDK compiler.

    Flash Builder 4.7 ships with two legacy Flex SDKs (3.6.0 and 4.6.0). These are only for Flex projects and cannot be overridden with the new ASC 2.0 compiler.

    Flash Builder 4.7 preview additionally ships with a captive version of the preview “AIR 3.4 SDK with ASC 2.0″ for ActionScript projects. This is in a separate plugin location. (In the preview, it is at \eclipse\plugins\com.adobe.flash.compiler_4.7.0.345990).

  9. David Roth says:

    Hi Alain,

    thank you – you found an inlining bug! If you declare a member variable, and initialize that variable with a function call which is inlined, when that inlined function contains a local variable declaration, you will see the problem you ran into. I will file a bug and fix this problem. In the meantime, as a work around, you can declare the member var, but don’t initialize is where it’s declared. Instead, initialize the member variable in the constructor of the class, such as:

    public class Main
    {
    private var result:Number; // = math01(12345); – don’t initialize here

    public function Main()
    {
    result = math01(12345);//initialize here instead
    }
    }

    With regard to the benchmarking question, I want the clarify that when a function is decorated with Inline metadata, that means that the function can be inlined when it is called, _not_ that function calls inside that function should be inlined. So in your example, I wouldn’t expect to see any performance improvements, as there is only one function call being removed.

    To see the effects of inlining, a better test would be something along the lines of:

    public function math01(data:Number):Number
    {
    var i:int;
    for (i = 1000000; i > 0; i–)
    {
    data = mathInner(data);
    }

    return data;
    }

    [Inline]
    final public function mathInner(data:Number):Number
    {
    return Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data));
    }

    This way 1000000 function calls will be removed, as the body of mathInner() and moved into the for loop.

    Hopefully this clears things up.

    Dave

  10. David Roth says:

    Hi Alain,

    Sorry, activations are a bytecode term, and not directly related to ActionScript. If an ActionScript function contains a with statement, or another function declaration, the compiler will generate an activation record. So basically as long as neither of these constructs are you, there shouldn’t be an activation.

  11. Workaround for embedding font with embed metadata, is to make an Ant Task using the old compiler just for this part.

  12. subb says:

    Hi Thibault,

    Where should we submit bug reports for the compiler?

    Thanks

  13. About fonts being removed from the embed tag –> With the new system how can I rename the fontFamily? We used to do this with embed but I can’t see a new way to do this. Am I stuck using the old compiler then? That would be a shame. What do you advise? Thanks!

  14. EMebane says:

    I updated MinimalComps to use the new font SWF embedding. It’s on GitHub here: https://github.com/ElliotMebane/minimalcomps
    and more details about using fontswf and embedding the font are here: http://www.roguish.com/blog/?p=550

  15. Thibault Imbert says:

    Hi guys,

    For info. We are going to reintroduce font support for embed in the next drop of ASC 2.0. I am sure you guys will appreciate.

    Thibault

  16. Peter says:

    Just wondering why the limit of 50 expressions? This limits the usability quite a lot, I know inline is supposed for small functions that are used a lot but there is also a need for inline for a larger function that is inlined 1 or 2 times in the whole framework. Especially useful in 2D/3D engines.

  17. Pavel says:

    Thibault Imbert,

    looks like new compiler (well I was reported about the issue with FB 4.7) doesn’t work properly with lazy statement ||=

    And also something else I cannot find out yet.

  18. khaled says:

    Nice Features but guys why did you remove the design view from Adobe Dlash builder 4.7 you really broke my heart !

  19. khaled says:

    Flash Builder 4.7 *

  20. Szymon Brych says:

    @khaled
    From Adobe Labs:
    “Although this beta release is not yet feature complete, we are excited for you to begin to experience the next generation of Flash Builder.”

    So, as far as I am concerned, lack of the visual preview doesn’t necessarily mean that it won’t be present in final version.

  21. Hi Dave! Very thanks for your explanations :-)

    I understood ! :-)

    The warning appaer just if i declare un new var in inlined Function Only if this inlined function is used several times (like in for loop) :-)

    It’s normal :)

    Directive [inline] Works moderately well.

    The big advantage of inlining is calling in the loop.

    But the time is relative well.

    If I do this

    for (i = 1000000; i > 0; i–)
    {
    data = Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data));
    }

    execution time is: 175 ms

    But if i do this:

    for (i = 1000000; i > 0; i–)
    {
    data = inlinedFunction(data);
    }

    [Inline]
    final private function inlinedFunction(data:Number):Number
    {
    return Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data));
    }

    Execution time is : 205 ms

    Dave thank you again for taking the time to answer me ;-)

  22. Dave, i forgot to say !!

    if a suppress the {} embrace and if i place all loop in the same line.. it’s pulverise the inline directive.. :)

    for (i = 1000000; i > 0; i–) data = Math.sqrt(Math.sqrt(data * data) * Math.sqrt(data * data));

    Execution time is: 130 ms

    this is also true for most loops !!

    Evidence that the ASC compiler can still improved .. :)

  23. Evidence that the ASC compiler can be improved .. :) (sorry)

  24. Hi guys, for french speaking visitors, I made a small article which explains [inline]

    http://www.pureas3.org/fr/la-nouvelle-directive-inline-du-compilateur-asc2-0

    :-)

  25. [...] projects, it’s pretty hard to keep yourself up to date with all the new stuff that has been added to the platform and really bring the engine to a next level. And it’s a bit pointless as well. So I had to [...]

     
  26. [...] : Inlining Functions with ASC 2.0 ActionScript Compiler (ASC 2.0) [...]

     
  27. John says:

    Hi.
    I’m very interesting about how you guys count a “50 expressions” in function body.
    Just look at that very simple example and please explain me how I should get a 50+ expressions here (I’ve counted 40 with get and set vars):

    internal static function __lineLineV( aposX:Number, aposY:Number, avecX:Number, avecY:Number,
    bposX:Number, bposY:Number, bvecX:Number, bvecY:Number,
    dst:Vec2 ) : void
    {
    var t00:Number = aposX * aposY;
    var t01:Number = aposX – aposY;
    var t02:Number = aposX + aposY;
    var t03:Number = aposX / aposY;
    var t04:Number = bposX % aposY;
    var t05:Number = aposX | bvecY;
    var t06:Number = aposX & aposY;
    var t07:Number = aposX ^ aposY;
    var t08:Number = aposX ^ aposY;

    dst.x = t00;
    dst.y = t01;
    }

    In any case 50 expr. is not enough. Please increase it at least to 100.

    Thanks for watching.

  28. HB says:

    I also think the limit of expressions should be raised. If inlining would be set automatically, I’d understand to have a low limit, but since the feature must be enabled explicitly, I’d say the constraint should be relaxed.

    Sometimes we are forced to make separate functions for readability while we’d prefer to inline them.

  29. lite3 says:

    package
    {
    public class Test
    {
    public function Test()
    {
    var a:int = 10;
    // In ASC2.0 not Erorr
    // In legacy compiler is Error
    a();
    }
    private function a():void { }
    }
    }

  30. Tufik says:

    Why the last 2 Chrome updates, no was updated Adobe Flash Player? Flash Player will not support more?

  31. HB says:

    @Tufik:
    I guess it’s because the new PPAPI interface used. Maybe it’s not yet well integrated into the build process, or there other issues being worked on.
    The classic interface NPAPI based Flash is still automatically updated as well, although the new one must be disabled first, something most users ignore or won’t care doing.

  32. [...] in the labs.adobe.com release of Flash Builder 4.7. Its the new ActionScript compiler, aka ASC2. Thibault does a great introduction blog post on the new [...]

     
  33. hey guys, first all I want to say great job and thanks.
    but I have got a problem with compiling my old project with new ASC2.0 . There is no errors or something when I exports release build but it never completes, I waited around hour but compilation didn’t end. I also looked into a task manager processes and saw that at first java takes around 25% of CPU but after few mins java stopped making any job and it is like that until I press cancel in Flash Builder from hour. I’m using Flash Builder 4.7 64-bit.
    is there any ideas why it could be happen ?

    Thanks,
    Georgi.

  34. Does Adobe has any decisions for use asc2.0 with Maven build system? And is available any Maven Repository with new SDK?

  35. Val says:

    Hi Sebastien… I have few questions about workers.
    How can i send to an worker complex objects of my own data types…serialization doesn’t work and it is very sad :(
    When Adobe is planing to release workers that are able to exchange any data types, starting from primitive and to very complex objects?
    I also noticed that workers are not able to load external files…Why we can’t use workers for background files loading?

  36. https://github.com/robotlegs/robotlegs-framework/issues/97

    New compiler break down Robotlegs – by breaking down usual behaviour of “||” operator. And now robotlegs doesn’t work in FB4.7.

  37. Shaun says:

    Is there an open issue for the Lazy Assignment ( ||= ) thing? I’ve looked, but can’t find anything. As there are already a number of backwards breaking changes I’d like to suggest fixing the behaviour of this operator as the old compiler behaviour was not ideal and this would be a good opportunity to fix it.

  38. Michael Montoya says:

    +1 for fixing ||= lazy assignment, it is breaking all our codebase and refactoring is not an option

  39. can I for example get access to microphone on the worker and record sound from it using your MicRecorder Class

  40. [...] The shift away from Flex means a shift towards “actionscript only” project workflow. Also known as “pure AS3″, these are software projects that are made without Flex and without Flash Pro. It is a coder-centric approach where visual and audio assets are added at develop-time (using embed code) or loaded at run-time. Actionscript projects now use the new ASC 2.0 compiler. [...]

     
  41. [...] or AI it still isn’t a viable platform, at least on mobile. Recent developments like the new Falcon compiler and AS workers are nice but Adobe is going to have to make more radical changes to the language [...]

     
  42. Rodrigo says:

    Hi Thibault, I don’t know if this is a known bug:
    I just tested AIR 3.5 and 3.6 with ASC2.0 in both cases when i instantiate a bitmapData from a swc library directly as the function parameter, nothing is rendered in the bitmap (the bitmap is already added on the stage).
    But if I create a variable for the bitmapData and then pass it to the function, works fine…

  43. rohit.khandare says:

    How to use Font Embedding in Flash builder 4.7

  44. [...] is a good post about ASC 2.0 : Introducing ASC 2.0 This entry was posted in AIR, Flex and tagged Adobe, AIR, ASC2.0, Flash Player. Bookmark the [...]

     
  45. hexagon says:

    What happened to the ASDoc Ant task in the new AIR 3.6 SDK? Removed?

  46. Jahiro says:

    When will SWC support for inlining be added? I keep getting this warning: The function lookupComponentByType could not be inlined, as no source could be found. Inlining func
    tions defined in a SWC is not supported.

  47. dimas_art says:

    So, what’s about maven builds based on new Action Script Compiler (ASC 2.0)?

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.