Posts Tagged objects

Why Objects Serialized With ByteArray Are So Small

Tags: , , , , , ,

We know that you can automatically serialize anything to a ByteArray and that it’s faster and smaller than XML or JSON, but why is it so much smaller? Today’s article investigates a bit and reveals the secret that makes it such an efficient format and how that can save you a lot of manual work when it comes time to deserialize the ByteArray.

Read the rest of this article »

6 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

Object Creation: Part II

Tags: , , , ,

As a followup to the previous article about object creation and a comment about an alternate object creation strategy, today’s article will expand the coverage of object creation. I will also discuss the performance (and generated bytecode) for creating non-empty objects to see if there are any redeeming factors to the “curly braces” (o = {}) approach.

Read the rest of this article »

7 Comments

Utility Functions For Objects

Tags: ,

Like most programmers writing non-trivial applications, I’ve piled up a lot of utility functions over the years. Most of them are simple and effective. They are short and get their job done. You or someone you know has probably written these functions, but maybe not in AS3. So today I’m going to share a few utility functions for Objects in AS3.

Read the rest of this article »

11 Comments

Map Performance

Tags: , , , , , , ,

I recently received an e-mail from Dmitry Zhelnin (translation) with a test he did concerning the speed of a couple ways to get a value for a key, which I like to call a map and Wikipedia likes to call an associative array. I’d been meaning to do a similar test for a while now and, guess what, I finally have! UPDATE: fixed miss test for fixed-size Vectors.

Read the rest of this article »

13 Comments

Loop Speed

Tags: , , , , , ,

AS3 gives you a good number of potential ways you can loop over collections. When Flash Player 10 first came out, I went ahead and tested out the new Vector class in a variety of ways. One of them was to pit it against the collections available in Flash Player 9: Array, Object, Dictionary, ByteArray, and even BitmapData. Below I’ll show you my test and discuss its results.

Read the rest of this article »

14 Comments

With Blocks

Tags: , ,

While plainly documented by Adobe in the Flash 10 AS3 Docs, it seems as though few programmers know about the with statement. I don’t use them much personally, but when a coworker came across one in my code recently and was puzzled, I figured I would write a quick article to cover their usage.

Read the rest of this article »

4 Comments

Dynamic Access Part 2: Dynamic Classes and Plain Objects

Tags: , , ,

Welcome to the second part of this series on dynamic access. Last time we covered indexing arrays and vectors. This time we’ll talk about dynamic classes and plain objects. These are definitely something to watch out for when writing performance-critical code.

Read the rest of this article »

No Comments

Dynamic Access: Part 1 (Indexing Arrays and Vectors)

Tags: , , ,

Many classes in AS3 are dynamic, meaning that you can add and remove their fields at runtime. This is powerful, but extraordinarily slow. This series will cover some common ways you might be inadvertently using dynamic access or using it too much. This will help you make your code faster. In the first installation of the series, I’m going to talk about the simple act of indexing an array or vector.

Read the rest of this article »

1 Comment

Indexing Anything

Tags: ,

Indexing is a little bit special in ECMAScript languages like AS3, AS2, and JavaScript. MXMLC will gleefully let you index just about anything, even if there isn’t a chance it’ll work.

Read the rest of this article »

1 Comment