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.

4

2 に答える 2

2

コレクションで ArrayCollection を意味する場合は、代わりにVectorを使用することをお勧めします。

ベクトルは、ArrayCollection よりも約 50 倍高速です。

データバインディングが必要な場合は、VectorCollectionを見ることができますが、パフォーマンスが Vector に近いとは思えません。

また、クラス SomeObjectType をどこにも拡張しない場合は、最終クラス SomeObjectType にすることで (特に iOS で) パフォーマンスを向上させることができます。

于 2013-06-21T20:49:36.730 に答える
0

辞書を使用して検索できます。これははるかに高速になると思います。一度だけ初期化する必要があります。

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);
        }
   }

}

したがって、「5」を含むすべての obj を返したい場合は、dict[5] を返すだけです。

于 2013-06-22T01:46:03.430 に答える