Posts Tagged array

Utility Functions: joinN and joinNLabeled

Tags: , , ,

It’s been a while since I’ve posted a utility function, but today I’m breaking the streak and posting a couple of related functions I frequently find useful in debugging: joinN and joinNLabeled. These functions are like Array.join and Vector.join, but they group elements of the array to make the resulting string much easier to read.

Read the rest of this article »

7 Comments

Sorted Array

Tags: , , ,

AS3 gives you arrays and a way to sort them, but no easy way to keep them sorted as you add elements to them. Today’s article discusses an easy way to do just that: build a sorted array and keep it sorted. As a bonus, the array provides very fast searching for the elements it contains.

Read the rest of this article »

19 Comments

Amazing Lookups Optimization

Tags: , , , , ,

Today’s article is about an unintuitive-yet-simple optimization you can use to hugely increase the speed of reading from Array, Vector, Dictionary, Object, and dynamic classes. Need I say more? Read on for this amazing speedup!

Read the rest of this article »

59 Comments

Even Faster Linked Lists

Tags: , , , , ,

Linked lists can be much faster than AS3’s Array and Vector classes if you use them under the right circumstances. It’s been over a year and a half since I last visited the topic, but today it’s time to update my LinkedList class. Read on for the freshly-optimized code and all-new performance testing and analysis!

Read the rest of this article »

47 Comments

Hidden Object Allocations

Tags: , , , , , , , , , , , ,

During some recent memory profiling I was reacquainted with just how many ways there are to unknowingly allocate an object in AS3. The problem is seldom the allocation itself, but rather the later garbage collection (GC) to delete those objects. Ever used a Flash profiler only to see a huge chunk of your CPU time going to [reap], [mark], or [sweep]? Yeah, that’s the GC at work. Today’s article talks about some of the ways you end up allocating objects in AS3 without using the new keyword. These subtle errors can end up costing you!

Read the rest of this article »

28 Comments

Loops With int and uint

Tags: , , , , , , , , ,

AS3 has two integer types: int and uint. In my experience, most AS3 programmers just use int everywhere and ignore uint. This is usually acceptable as the need for unsigned integers is rare compared to their signed counterparts. However, there are significant performance differences between the two. Read on for the impact of uint on your loops. The original version of this article’s performance test contained a small-but-critical error that led to a lot of incorrect analysis and results. This version of the article has been corrected.

Read the rest of this article »

8 Comments

The Importance of Pre-Allocation

Tags: , , , ,

When you construct an Array or a Vector, you can specify an initial size. Why would you do this?There are various reasons you may want to reserve initially-unused slots for logic reasons, but are there any performance gains to be had by pre-allocating this space for an Array or Vector you intend to completely fill right away? Today I’ll take a look to see just how much performance can be gained by pre-allocating Arrays and Vectors.

Read the rest of this article »

3 Comments

Constructing Arrays

Tags: , ,

In AS3, you can create an Array can be created with special syntax: myArray = []. You can even fill the Array with values all in one go: myArray = [1,2,3,4,5]. This is a nice shorthand that saves some typing compared to using the constructor: myArray = new Array(1,2,3,4,5). But, which way is faster? Today we find out! UPDATE: added a third way of creating arrays

Read the rest of this article »

9 Comments

Dynamic Field Access

Tags: , , , , , , , , ,

AS3 has an interesting feature that is sometimes used to great effect: dynamic classes. These classes can have fields added and removed to them and used like any other field. You can even make your own dynamic classes with the dynamic keyword. However, all of this fancy functionality comes at a steep performance cost. How steep? Read on to see just how steep.

Read the rest of this article »

10 Comments

Holding DisplayObjects

Tags: , , , , ,

I recently received an e-mail from asking which is faster: a DisplayObjectContainer or a Vector of DisplayObject. To ask this is to question whether or not we can do better than the Flash Player’s native container of DisplayObjects using AS3. It turns out that we can. Read on for several ways to improve on DisplayObjectContainer‘s speed.

Read the rest of this article »

4 Comments