开发者

How many successive calls is too many?

I'm debugging some code and see a loop where an event is dispatched and a remote call is made for every record.

Everything was working fine until there were several hundred records (700) to be a exact. Is that going to make the flash player chug? Should I move to a queued system? How many records is too many?

Thanks for any helpful tips.

Here is the updated method that sends the successive calls out:

var counter:int= 0;
        for each ( var item:ObjectVo in itemColl)
        {
            counter = counter + 1;
            var evt:DataValidationEvent = new DataValidationEvent();
            evt.myItem = item;
            evt.eventType = DataValidationEvent.EVENT_TYPE_PASTE_FROM_EXCEL
            i开发者_JAVA百科f( counter == ( itemColl.length ) ){
                evt.isLastCall=true;
            }else{
                evt.isLastCall=false;
            }
            evt.dispatch();
        }

This is the event handler. It gets called only once, after 'isLastCall' is set to true.

private function addItemsFromList( item:itemVo ):void{
            var myObj:ObjVo = new ObjVo();
            myObj.description = item.description;
            myObj.rule = item.objRule;

            this.itemsColl.addItem( myObj );
            this.itemsColl.itemUpdated( myObj );
            this.itemsColl.refresh();
        }


If you're making several hundred remote calls, it might just as well be the server, that's giving up on you. I'd be wondering if Flash Player is the real bottle-neck here. The AVM2 can make a few thousand calls within a few milliseconds.

All I can advise with this little information is to measure the time your loop takes to complete and if it's really that loop that takes time, try to find the most expensive bits by selectively commenting out parts of the loop body.

edit:

Good tweening engines peak at animating a handful of properties on 25K objects at 60FPS, which is well over a million calls (and rendering of 60 frames) per second. Something must be quite wrong with your code.

Things that are slow about your code:

  • instantiation is orders of magnitude more expensive than simple calls. In performance critical scenarios (which this one actually isn't), you're far better off with object pooling or restricting yourself to primitives.
  • calling function objects instead of methods is also slow - as a consequence of this and the previous problem, the commonly practiced event mechanisms are slow as hell. Still 700 per frame should be no problem.
  • the last bit seems the most disturbing one. without knowing what handles the event, it's hard to know, but worst case with every event dispatched, you process all the items, which gives you O(N^2) runtime cost and results in N*(N+1) the cost of a single iteration and if a single iteration means redrawing the grid, then this can really go wrong. In any case, I think dispatching one event after the whole loop should suffice.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜