I’m playing with Flex data Providers and actually I’m testing ArrayCollection. There are 3 ways to populate an Array collection:
- Initialize an ArrayCollection and then use its addItem() method (which accepts any Object type)
- Initialize an ArrayCollection, access its “embedded” Array by using the source property (ie: myArrayCollection.source) an then push objects inside this one
- Initialize an Array, populate it and then initialize an ArrayCollection by passing the Array to its constructor (ie: myArrayCollection:ArrayCollection = new ArrayCollection(myPreviousDefinedArray))
Last technique is (as far I saw) absolutely the fastest , I did a test in which I populated a collection with 300,000 objects and it taken about 9 seconds instead of 32 (350% slower) of first one! The second technique is also faster than the first, but the third is better.
So, what I learned is that addItem() should used only to add few items, instead for huge collection should be avoided in favor of the third technique described in order to obtain better performances.