Archive

Archive for September, 2009

Flex 4 Text Performance Issues

September 24, 2009 Leave a comment

We have been running into performance issues with a new MMSP level application where we render anywhere from 1 to thousands of items. We narrowed it down to the List, DataGroup, ItemRenderer, and related items and decided to run some tests to see what about them was taking so long.

We created an app that creates 5 lists, each with their own data group and item renderer files. We created one with vectors/gradients only (NoLabelNoBind), vectors/gradients with labels and no binding, vectors/gradients with labels and binding, and then two more with richtext in stead of labels.

We rendered 100, 200, 300, 400, and then 500 items, all of which finished except the 500 item test, where it got a 15 second script timeout exception thrown. Maybe our tests are bogus and we are doing something wrong, but we are ignorant of those techniques if that is the case. The bottom line from this test app is to use labels where RichText isn’t needed and don’t use binding but in stead set the properties of the labels from the Dto/Vo objects as the renderer receives the new item.

Per the adobe help docs, we tried adding the “useVirtualLayout” property to the layout property on the datagroup and list with the same results.

Speed Test

Speed Test

The associated source can be found here.

PUNQ 1.0 released

September 15, 2009 Leave a comment

I’ve been working on a free IT Search tool for the past couple of months at my company called PUNQ.

See the official press release here, a summary on the tool here, and the you-tube help videos here.

I think the toughest part of the project was integrating the code base among platform specific features including a web (flex) version and an air version for desktop apps.

Categories: Uncategorized

So you have memory problems in your Flex application?

September 3, 2009 Leave a comment

First, if you aren’t already acquainted with the memory issues in the flash player, browse through some of these links:

Grant Skinner:

Sean Christmann: http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/

Alex Harui:

Adobe official docs: http://livedocs.adobe.com/flex/3/html/help.html?content=profiler_6.html

I would like to add a technique to the collective knowledge that I have implemented in our MVC framework and propagated through our legacy code base: IDisposable.

The contract of IDisposable is very simple, exposing a lone method: dispose(). An implementation of the interface has the following responsibilities:

  1. Follow the rules of the aforementioned links (e.g. removing event listeners)
  2. Call dispose on any IDisposable children that he is responsible for.
  3. Explicitly set all class level non-simple types to null, including splicing arrays, and deleting dictionary/object keys.

The reason for number 3 is very simple. Take a look at the following diagram taken from the garbage collection overview by Grant:

Credit to Grant Skinner: http://www.gskinner.com/blog/

Credit to Grant Skinner: http://www.gskinner.com/blog/

Since the first pass of the flash garbage collector is based off of reference counting, the goal is to remove all references that you can control in order to optimize for the collector. Let’s see an example.

private var _string1:String = "Don't bother disposing of me";
private var _a:Array;
private var _o1:Object;
private var _o2:Object;
private var _o3:Object;

function ohSnap():void
{
    _o1 = {label: "sweet"};
    _o2 = {label: "awesome", sweet: _o1};
    _o3 = {label: "cool", awesome: _o2, sweet: _o1};
    _a = [_o1, _o2, _o3];
}

Even if this array and collection of objects ends up white in the mark and sweep diagram above, they remain in memory until the second phase of the collector is activated. Why?

Lets count the references of the objects created in ohSnap:
o1: 4 references, by the array, o2, o3, and _o1.
o2: 3 references, by the array, o3, and _o2.
o3: 2 references, by the array and _o3.
a: 1 reference by _a

Now, let’s go on ahead and optimize our destruction by cleaning up these references in our dispose method:

public function dispose():void
{
    for ( var i:int = _a.length-1; i > -1; i-- )
    {
        var o:Object = _a[i];
        for ( var key:String in o )
        {
            delete o[key];
        }
        _a.splice(i, 1);
    }
    _o1 = null;
    _o2 = null;
    _o3 = null;
    _a = null;
}

Deleting the keys of the objects removes the references of o1 in o2 and o3, and o2 in o3, while splicing the array removed the references to o1, o2, and o3. Finally, the class level references to the objects were removed, leaving a reference count of zero for the three objects and array.

In addition to having the marksweep collection method run less because the reference count method removes the objects first, implementing a standard contract in your applications for all objects makes memory management, such as identifying leaks easier because the cleanup of each object is in a standardized place.

SystemManager.application == null using SWFLoader or Loader

September 2, 2009 3 comments

So you need access to the application property inside the system manager you just loaded using SWFLoader or Loader huh?

There are two options:

1. Listen for the FlexEvent.APPLICATION_COMPLETE event on the System manager after the loader fires the Event.INIT event.

However, that sucks if you need access to the application before it has finished its construction.

While it isn’t ideal for my situation (I wanted access to the application before the initialize event was fired), I was able to get hold of the application after the initialize event had been fired, but before the creation complete event had been fired.

2. Listen for the Event.ENTER_FRAME event on the system manager, and check if the application property is not null. Tada. Crappy I know, but what can you do?

Also, remove the event listener once you have access to the application (unless you want it?).

Casting swfLoader.content as SystemManager

September 2, 2009 7 comments

So I was trying to load an application into another and was using SwfLoader.

When I received the INIT (or COMPLETE) events from the loader, I was trying to cast the .content property as SystemManager (since that’s what it is) but the type cast was failing.

The solution is to set the SwfLoaders loader context property with a new context and pass in the current application domain.

var loader:SwfLoader = new SWFLoader();

loader.loaderContext = new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDoman));

Now you can cast the content property as a SystemManager.

Yippie.

Categories: Flex Gotchas
Follow

Get every new post delivered to your Inbox.