0

I have just watched this video on Performance Tips and Tricks for Flex and Flash Development and it lists 3 things that are measured when using and creating Flex.

  • Creation
  • Validation
  • Rendering

How do I measure these items on my own projects? In my case and more specifically for this question, how do I test how long it takes to create my item renderer, validate it and render it?

Is the total of all these events the total time I should use when testing the performance of the item renderer? I mean once it's created then what matters is just the rendering and validation correct?

What I mean is if I have an item renderer I THINK I could find out the creation time by using the following code:

 <itemrenderer initialize="trace('initialized at='+getTimer())" creationComplete="trace('created at='+getTimer())" />

Not sure if this is right. But what about validation and rendering?

zero323
  • 322,348
  • 103
  • 959
  • 935
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231

2 Answers2

1

You're on the right track.

The gist is to get two values from getTimer and use the difference to determine how long the operation took.

Ideally you're first getTimer() will be in the constructor. If you're dealing with MXML components; there is no constructor so I would use the preinitialize event. We can call this number timer1.

The creationComplete event is fired when the component initialization is complete. That includes the first 'render' event. We can call this nnumber timer2.

Perform:

timer2-timer1

To track the creation piece of the Flex Component's lifecycle. This will also include the first render process.

For the purposes of a Flex component; I'd say that Render is the process of running commitProperties(), measure(), and updateDisplayList(). The trick to tracking this is that you don't know which one--if any--will be called because it depends what was invalidated.

Validation is an ongoing process as the component runs; which causes a component to be re-rendered.

I would probably listen to the render event to start you timer; and the updateComplete event to track when a component's rendering is complete.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
0

Here's what I've got so far:

timeLabel.text += "\nAbstractDataGridItemRenderer: " + testGridItemRenderer(AbstractDataGridItemRenderer, data, 50);

And the function:

        public function testItemRenderer(renderer:Class, data:Object, iterations:int = 1000, resetTime:Boolean = false):int {
            var layoutManager:LayoutManager = LayoutManager.getInstance();
            var time:int = getTimer();
            var itemRenderer:IItemRenderer;

            for (var i:int;i<iterations;i++) {
                itemRenderer = new renderer();
                itemRenderer.data = data.name + i;
                itemRenderer.width = 300;
                itemRenderer.height = 30;
                itemRenderer.y = i * 30;
                itemRenderer.label = LabelUtil.itemToLabel(data, "label");
                addElement(itemRenderer);
                //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                layoutManager.validateClient(ILayoutManagerClient(itemRenderer), false);
                //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
            }

            if (resetTime) {
                time = getTimer();
                for (i=0;i<iterations;i++) {
                    itemRenderer.data = data.name + i;
                    itemRenderer.label = LabelUtil.itemToLabel(data, "label");
                    //addElement(itemRenderer);
                    //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                    layoutManager.validateClient(ILayoutManagerClient(itemRenderer), false);
                    //trace("initialized = " + ILayoutManagerClient(itemRenderer).initialized);
                }
                return getTimer() - time;
            }

            return getTimer() - time;
        }

I don't know if this is right but it's giving me some numbers to work with. I'd rather not add it to the stage but it seems I have to do that to get it to initialize.

Initialized is true when an object has been through all three phases of layout: commitment, measurement, and layout.

Update. I added a reset phase. This leaves the rendering phase.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231