Filed Under (AIR, ActionScript, Flex) by jonr on November-4-2008

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.
  • DZone
  • Digg
  • del.icio.us
  • Reddit
  • Facebook
  • LinkedIn

Comments:

[...] 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. … Read more [...]

Craig Newroth on November 5th, 2008 at 12:37 pm #

I thought that was a good idea. I voted for it!

teddy on November 6th, 2008 at 3:48 am #

got the same problem with my project, change back from arraycollection to array for some function.

Jon Rose’s Blog » Blog Archive » Flex Immaturities on November 7th, 2008 at 6:01 am #

[...] similar pain for me was ArrayCollection (see previous post).  In my previous post, I didn’t discuss our attempts to extend ArrayCollection to control [...]

Campbell Anderson on November 20th, 2008 at 8:41 pm #

Wait until you start dealing with Hierarchical collections (multidimensional Arraycollections) where events have to propagate up the tree. ;) Try getting any decent sized tree happening and you may as-well have just started with Arrays.

Campbell Anderson on November 20th, 2008 at 8:50 pm #

P.S. if its just the events that are slow. override the “dispatchEvent” method (part of IEventDispatcher) to have a switch to stop it, or stack the events for later disptach.

[...] James and I have posted our latest video, Performance Pitfalls of Flex’s ArrayCollection.  It is a follow-up to my recent post on the problems we encourtered with ArrayCollection. [...]

Velo on November 21st, 2008 at 6:15 am #

I’m not 100% of this, didn’t try. But, instead of returning a List you could change you method to return an Array[]

Just add an extra line and invoke List.toArray(new ?[0]);

I think is better then using legacy-collection setting.

Matt on November 21st, 2008 at 12:51 pm #

Interesting find. Could you enable the legacy-collection setting and then have your result handler wrap the resulting array in an ArrayCollection before passing it on to the rest of the system? That way you get the best of both worlds (no events fired during deserialization but still get the benefits of ArrayCollection later) with only localized code changes. Or is that what you’re doing already?

jonr on November 21st, 2008 at 3:25 pm #

Thanks for the comment Matt! I actually tried the approach you are describing. I explain what happened in the following post: http://ectropic.com/wordpress/?p=63.

[...] of working with large data sets in Flex. For additional details read Jon’s blog about the performance problems with ArrayCollection and check out the associated bug in Flex’s bug db. We’ve also put together two Flex [...]

[...] enable databinding. You could alter it slightly to handle ArrayCollections, but as we can see from Jon Rose’s blog and examples, you lose performance with a high number of [...]

Post a comment
Name: 
Email: 
URL: 
Comments: