Skip navigation
Currently Being Moderated

Problem with "new Group()" performance

Mar 21, 2010 8:42 AM

Hello

 

I need to create many spark.components.Group objects (more than 10000) and have some performance problem. In many cases new object was created in 0-5 ms, but sometimes in 266-700 ms.

 

This is output from my test app (code below):

[Time] - [Count]

0 - 91035
1 - 7308
2 - 393

3 - 365

4 - 408
5 - 404
6 - 66

7 - 3

8 - 3
9 - 2
10 - 1

12 - 1

13 - 1

16 - 1

19 - 1

24 - 1

39 - 1

63 - 1

67 - 1

210 - 1

260 - 1

266 - 1

690 - 1

 

And code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" applicationComplete="windowedapplication1_applicationCompleteHandler(event)">
    <fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;
 
        import spark.components.Group;
 
        private var container:Array = new Array();
 
        protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void {
            var map:Object = new Object();
            var i:int, start:int, stop:int;
            var grp:Group;
            for(i = 0; i != 100000; i++) {
                start = new Date().getTime();
                grp = new Group();
                stop = new Date().getTime();
                if (!map.hasOwnProperty(stop - start)) {
                    map[stop - start] = 0;
                }
                map[stop - start]++;
                container.push(grp);
            }
 
            for (var key:* in map) {
                trace(key + " - " + map[key]);
            }
    }
 
    ]]>
    </fx:Script>
</s:Application>

 

 

Can you test this code in yours computers?

Anybody know where is a problem? I don't have any applications run in background. etc...

 

Testes on SDK: 4.0 (default in Flash Builder 4 b 2), 4.0 build 13875, 4.1 build 14741

 

Mariusz Dalewski

 
Replies
  • Currently Being Moderated
    Mar 21, 2010 9:15 AM   in reply to Mariusz Dalewski

    That's what I get :

     

    0 - 99108
    641 - 1
    578 - 1
    422 - 1
    31 - 2
    328 - 1
    15 - 328
    16 - 554
    594 - 1
    500 - 1
    282 - 1
    703 - 1

     

     

    My laptop is maybe a bit faster.

     

    This has nothing to do with group ! I'm guessing the flash virtual machine has to perform some memory management in between or some other operations.

     

    Look at the result when using a vector of groups instead :

     

    0 - 89985
    1 - 7899
    2 - 412
    3 - 385
    4 - 422
    5 - 655
    6 - 204
    7 - 7
    8 - 6
    9 - 5
    10 - 3
    11 - 4
    12 - 1
    13 - 1
    14 - 3
    17 - 1
    37 - 1
    19 - 2
    22 - 1
    23 - 1
    34 - 1
    30 - 1

     

     

    Side note, more than 10.000 groups ??? Are you sure you can't use something more lightweight ? ( Sprite, UIComponent, etc ) A group is a container with many, many functionalities and it comes a cost.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2010 11:08 AM   in reply to -BoNzO-

    Here are my results with a few classes:

     

    spark.components.Group:

     

    0 - 87676
    1 - 10563
    2 - 340
    3 - 346
    4 - 349
    5 - 480
    6 - 222
    7 - 6
    8 - 4
    9 - 1
    10 - 1
    11 - 1
    76 - 1
    13 - 1
    14 - 2
    16 - 1
    12 - 1
    407 - 1
    472 - 1
    26 - 1
    94 - 1
    31 - 1

     

    mx.containers.Canvas:

     

    0 - 79601
    1 - 18534
    2 - 287
    3 - 258
    4 - 284
    5 - 383
    6 - 328
    7 - 243
    8 - 42
    9 - 11
    130 - 1
    11 - 2
    324 - 1
    13 - 2
    14 - 3
    10 - 3
    18 - 1
    12 - 9
    21 - 1
    741 - 1
    504 - 1
    27 - 2
    28 - 1
    351 - 1

     

    mx.core.UIComponent:

     

    0 - 89460
    1 - 8748
    2 - 337
    3 - 382
    4 - 317
    5 - 527
    6 - 209
    7 - 3
    8 - 2
    9 - 3
    42 - 1
    99 - 1
    12 - 1
    462 - 1
    14 - 2
    15 - 1
    116 - 1
    118 - 1
    124 - 1
    30 - 1
    31 - 1

     

    Sprite:

     

    0 - 98957
    1 - 1030
    2 - 1
    5 - 11
    6 - 1

     

    spark.primitives.Rect:

     

    0 - 99598
    1 - 402

     

    spark.primitives.supportClasses.GraphicElement:

     

    0 - 99598
    1 - 402

     

    As Bonzo mentioned this doesn't seem to be a Group problem as Canvas also has some long times.  UIComponent is lighter than both Canvas and Group and it still has  a couple entries longer than a few ms.  Notice that using Sprite or GraphicElement is much faster.  GraphicElement is very lightweight, are you able to use it instead of a Group? 100,000 Groups seems like a lot, can you explain your use case, maybe there is a way to use virtual layout to minimize the number needed at any one time?

     

    I think the container.push() call might be causing a lot of the delay, if you use:

     

    private var container:Array = new Array(100000);
    ...
    container[i] = grp;

     

    You should see less large delay times.  It might be good to try using a Vector instead of an Array like Bonzo suggested too.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2010 5:04 PM   in reply to Shongrunden

    The operating system is stealing cycles for various things and delaying your

    code.  Flash may execute actionscript in a single thread, but that thread is

    constantly stopped in order to give other programs on your computer time to

    run.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points