Archive for category AS3

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

Improving Vector3D

Tags: , , , , ,

The Vector3D class debuted in Flash Player 10.0 as Adobe’s official implementation of, well, a 3D mathematical vector (not the pseudo-Array class Vector). Weirdly, it has a w component and is therefore technically a 4D vector, but its API inconsistently make use of the fourth dimension. There are also strange oversights, inefficiencies, and functionality it really should have always had. Read on for my custom Vector3D derivative—Vector3DExt—that fixes all of these problems by extending and improving on the original.

Read the rest of this article »

5 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

Better OOP Through Namespaces

Tags: , , ,

Namespaces may make poor function pointers, but you’d be wise to not write them off so quickly. It turns out that they have an altogether different usage that can help you blend the speed advantages of public fields with the encapsulation and information hiding of getters and setters. Read on to learn more about this lovely compromise.

Read the rest of this article »

8 Comments

Advanced break and continue Statements

Tags: , , , ,

There’s more to AS3’s break and continue statements than you might think. Chances are, you’ve used them to skip to after a loop (break) and skip the current loop iteration (continue), but they can do so much more. Today’s article will cover some of the advanced ways to use the break and continue statements in AS3 resulting in nicer—and maybe even faster—code.

Read the rest of this article »

15 Comments

Make Math.sqrt Twice As Fast

Tags: , ,

Today’s article shows you how to double the speed of Math.sqrt, which should be useful to many Flash apps as it is a very common operation. For example, the difference between two points involves a square root: sqrt(dx*dx+dy*dy). Read on to learn how!

Read the rest of this article »

20 Comments

Even Faster Trig Through Inlining

Tags: , , , , ,

Last week’s article showed you a way to improve the performance of trig functions like Math.sin by almost 4x by using lookup tables. This week’s article will go even further and show you how to increase this speedup to over 10x!

Read the rest of this article »

17 Comments

Faster Math.sin and Math.cos Through Lookup Tables

Tags: , , , ,

Trigonometry functions like Math.sin and Math.cos are widely used in AS3 games and other apps that make intensive use of graphics, sound, or physics. Today’s article shows you a way to trade a little bit of memory for much faster trigonometry computations, which can seriously speed up any app that makes heavy use of Math.sin, Math.cos, and the like. Keep reading for the class that’ll help you do this, a demo app, performance testing, analysis, and more. (UPDATE: optimized thanks to skyboy)

Read the rest of this article »

16 Comments

XML Speed

Tags: , , , , ,

XML is widely used in AS3 applications for everything from simple configuration files to complex networking protocols. AS3 even includes 10 operators in its syntax specifically to make XML easier to work with. This often leads to AS3 developers loading XML documents and then just leaving them as an XML objects. XML’s performance begins to seep into the rest of the AS3 application. Today we look at just how much this can slow down our apps.

Read the rest of this article »

6 Comments