Flex ArrayCollection Performance

A few weeks ago my co-workers and myself spent a few hellish (but fun) days with significant performance issues on the eve of our first release of a Flex application we are building for a Gorilla Logic client.  First off, the majority of the issues were unrelated to Flex, but architectural choices outside of the presentation tier that we do not have much say in.  However, we did encounter a major challenge with Flex’s ArrayCollection.

Due to a somewhat unusual data set, we have a large number of ArrayCollections being returned in our Object graph, and we were experiencing a large time lag between when Flex reached the result handler and after BlazeDS had finished its work.  Times ranged from 10-60 seconds depending on the size of the data set.  After a decent amount of analysis, we discovered most all of this time was related to the performance hit of instancing an ArrayCollection.

By our testing, we were experiencing an 18x difference between instancing a large number of Arrays versus ArrayCollection.  We measured this with a simple program that just instanced 100,000 Arrays and then 100,000 ArrayCollections.  In addition, we tested with BlazeDS returning Arrays versus ArrayCollections and saw the same 18x difference.

The solution for us was to have BlazeDS return Arrays instead of ArrayCollections, with the legacy-collection setting.  This is obviously a decent trade off, as Arrays lack much of the essential functionality of ArrayCollection.  The root problem with ArrayCollection is the number of events that dispatches, and there are the methods for enabling and disabling “auto updates” to turn this off.  However, it is possible, but difficult to do this before Flex client reaches the result handler.

Beyond making instancing ArrayCollection faster, it would be nice to have the option to easily disable this behavior with a configuration property.  Here is the feature request I made: http://bugs.adobe.com/jira/browse/SDK-17916.  Please go vote for it!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • LinkedIn
  • DZone
  • Facebook
  • Digg
  • del.icio.us
  • Reddit
This entry was posted in Historic. Bookmark the permalink.

One Response to Flex ArrayCollection Performance

  1. Eric Hermann says:

    I have always felt uncomfortable on how overused Flex complex collections are compared to simply using arrays. In so many cases, people use ArrayCollections when a simple array would suffice. Your blog so clearly demonstrates why I am so paranoid about using these types of collections. Unfortunately, I tried turning on the legacy-collection setting, and I did not see such a noticeable performance boost. Since, spark dataProviders require a more complex object, I still have to set the returned array’s to an ArrayCollection object. Did you have to do more on the flex side to take advantage of this performance increase?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>