1

Suppose we have some custom object type:

class SomeObjectType {
   public var intProperty1:int;
   public var intProperty2:int;
   public var intProperty3:int;
   public var stringProperty1:String;
   public var stringProperty2:String;
   public var stringProperty3:String;
   public var stringPropertyThatActuallyIsInt1:String;
   public var stringPropertyThatActuallyIsInt2:String;
   public var stringPropertyThatActuallyIsInt3:String;
   ...
   %ABOUT_20_ANOTHER_PROPERTIES_THAT_I_WON'T_USE%
}

We have a collection of more than 20k instances of these objects. And we have just 1 text input that is actually search filter. User can type in this filter field anything he want and if his filter matches with ANY of first 9 fields I described before we should leave this object in collection. Just simple items filtering.

And let me describe how it works in our project now. This algorithm casts all these properties to Strings, concatenate them, and search using indexOf() != -1 method. This is really slow. It takes about 500-900ms on my dev machine and about 3-4s on iPad on every filter change. Horrible statistics, isn't it?

Small note: we use this algorithm in different 3 places in app and objects differs from object I described above but idea is same. I believe that it is a good idea to compare int to int, string to string (implementing some of fast algorithms(there are lots if them)), and convert string that is actually to int and compare them as int to int, but object differs a lot so I need some common algorithm.

2 Answers 2

2

If by collection you mean ArrayCollection, I would recommend to use Vector instead.

Vectors are around 50 times faster then ArrayCollections.

If you need databinding, you could have a look at VectorCollection, but I can't imagine the performance to be anywhere close to Vector.

Also if you are not extending class SomeObjectType anywhere, you could gain some performance (especially on iOS) by making it final class SomeObjectType.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for advice to make class final. I'll try to use it tomorrow. You're right about ArrayCollection - we use them. But we cant change ArrayCollection to Vector because Adobe ADEP uses it as ArrayCollection only. I don't think that converting ArrayCollection to (new!) Vector will help with performance
@murdoc Why? -> "I don't think that converting ArrayCollection to (new!) Vector will help with performance". You could make a copy of your collection in a Vector and run some test.
Also have a look at the answer here: stackoverflow.com/questions/2672096/…
@murdoc Could you you give some feedback please? How much performance did you gain? And what have you done. I am very interested to know. Thank you. :)
Hi! Thanks for your great advise! Let me describe what I have done. As far as I know you are familiar with flex so you must know what is filterFunction property for ArrayCollection and how it works. In our project we convert every search field to string and concatenate them INSIDE filter function. So it looks like private function someFilterFunction(item:Object):Boolean {var properties:String = String(property1) + String(property2) + String(property3)}; return propertiesString.indexOf(searchFilter) != -1;
|
0

You can use dictionary to search, I think it will much faster, you just need to init for one time.

var dict:Dictionary = new Dictionary();

//get properties,in you obj, they are intProperty1,intProperty2 etc,exclude prototype
var properties:Array = ObjectUtil.getClassInfo(SomeObjectType, ["prototype"]).properties as Array;

for each (var obj:SomeObjectType  in yourArrayCollection) {

   for (var i:int = 0; i < properties.length; i++) {

        var qname:Object = properties[i];
        var k:String = qname.localName;

        var v:String = obj[k];

        if (dict[v] == null) {
            dict[v] = [];
        }

        //add only one time
        if ((dict[v] as Array).indexOf(obj) == -1) {
            (dict[v] as Array).push(obj);
        }
   }

}

So if you want return all objs contains "5", just return dict[5]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.