Macromedia Flex Macromedia Flex
Performance regarding String Concatenation & StringBuilder
  Home

Jul 13, 2006 - Performance regarding String Concatenation & StringBuilder
Insight into the internals to understand performance implications.

 

In the land of the Flash Player, the new AVM supports what's called fast string concatenation. In the past if you did:

string1 += string2

It allocated a new buffer object, and would then transfer both prior string buffers into the new one and return the new string object.

In Flash Player 8 they added they added support for prefix strings. This supported a linked list concatenation of string objects where one string can have a prefix string object as well as its own string buffer. This allowed a smaller string object to hold a raw string bugger and a pointer to another string object. As a result, certain operations would cause a string object to de-link it's structure into one string buffer.

The end result: Concatentation for strings only allocated one 16-bit string object with no memory copying which results in faster speeds for the concatenation operation.

With the new StringBuilder object, an entirely new technique is introduced; a large buffer is utilized to hold the strings being addded. When the buffer is fully leveraged (aka full) it will auto-grow in size to accomodate by some kind of increment factor. The benefit is that it doesn't require the constant memory allocations as in the previous approach, but still requires some memory to facilitate the copying and allocations none-the-less.

Bottom Line: The new AVM in Flash Player 9 requires less memory and increases performance for string concatenation whether you're using simple concatenation or using the StringBuilder object. The simple approach may have a slight edge due to it's reduced overhead; but either way use whatever is convenient for you.

Thanks to Werner Sharp from Adobe for the insight into this.

File Details
Created On Jul, 13, 2006 by Scott Russel
Last Modified On Jul, 13, 2006 by Scott Russel
Group: Tips and Articles
Flex Versions: 2.0
Category: Actionscript
Type: Tip
Difficulty: Intermediate
Keywords:
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80