简体   繁体   English

AS3 / Flex性能-新的ArrayList与ArrayList.removeAll()

[英]AS3/Flex Performance - new ArrayList vs. ArrayList.removeAll()

What is actually faster? 实际上什么更快? Simply creating a new ArrayList/ArrayCollection or re-using an existing one and remove its elements? 只是创建一个新的ArrayList / ArrayCollection或重新使用现有的ArrayList / ArrayCollection并删除其元素?

I'm developing for mobiles where performance is always an issue, so I'm after the fastest method. 我正在为始终是性能问题的手机开发产品,因此我追求最快的方法。

Here's an interesting blog post on optimization of clearing an ArrayList/ArrayCollection. 这是有关清除ArrayList / ArrayCollection的优化的有趣的博客文章 Apparently, setting mycollection.source = new Array() is significantly faster than mycollection.removeAll() with large data sets, as removeAll ensures that all event listeners are removed. 显然,设置mycollection.source = new Array()的速度明显快于使用大型数据集的mycollection.removeAll() ,因为removeAll可确保删除所有事件侦听器。

As this is the case, most likely new ArrayList would beat ArrayList.removeAll(), but new source Array may be the better option, as it should have less of an impact on bindings/listeners. 在这种情况下,很可能新的ArrayList将击败ArrayList.removeAll(),但新的源Array可能是更好的选择,因为它对绑定/侦听器的影响较小。

even faster is mycollection.source = []; mycollection.source = [];甚至更快mycollection.source = []; (as opposed to mycollection.source = new Array() ) (与mycollection.source = new Array()

Another option is to use linked lists and object pools. 另一种选择是使用链接列表和对象池。 Object pools allow the objects to have their properties re-written instead of deleting an object and creating a new one. 对象池允许重写对象的属性,而不是删除对象并创建新的对象。 If you then keep them in a linked list instead of an array, looping through them is a lot faster. 如果随后将它们保留在链接列表而不是数组中,则遍历它们会快得多。 So if you just want to loop through a bunch of objects, go with linked lists, but if you need to do any sorting, then the array and vectors would be faster. 因此,如果只想遍历一堆对象,请使用链接列表,但是如果需要进行任何排序,则数组和向量会更快。

Another concern is memory use. 另一个问题是内存使用。 not just for keeping applications running memory smaller, but the more objects you declare, the more work the garbage collector has to do when it comes time for clean-up. 不仅是为了使运行的应用程序的内存更小,而且声明的对象越多,垃圾收集器清理时要做的工作也就越多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM