连续调用多少次才算太多?
我正在调试一些代码,并看到一个循环,其中调度事件并对每条记录进行远程调用。
一切都工作正常,直到有数百条记录(确切地说是 700 条)为止。这会让 Flash 播放器卡顿吗?我应该转移到排队系统吗?多少条记录太多?
感谢您提供任何有用的提示。
以下是发送连续调用的更新方法:
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
if( counter == ( itemColl.length ) ){
evt.isLastCall=true;
}else{
evt.isLastCall=false;
}
evt.dispatch();
}
这是事件处理程序。在“isLastCall”设置为 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();
}
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
if( 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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要进行数百个远程调用,那么也可能是服务器放弃了您。我想知道 Flash Player 是否是这里真正的瓶颈。 AVM2 可以在几毫秒内发起数千次调用。
我能用这些小信息建议的是测量循环完成所需的时间,如果确实是那个循环需要时间,请尝试通过有选择地注释掉循环体的部分来找到最昂贵的位。
编辑:
优秀的补间引擎能够以 60FPS 的速度对 25K 对象上的少数属性进行动画处理,远高于每秒一百万次调用(以及 60 帧的渲染)。您的代码一定有问题。
代码缓慢的地方:
N*(N+1)
单次迭代的成本,如果单次迭代意味着重新绘制网格,那么这真的可能会出错。无论如何,我认为在整个循环之后调度一个事件就足够了。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:
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.