FP10: Vector vs Array

Update 2 (Read first):

I noticed there are still some trackbacks to this post. To clear things a little bit up. This post is 2 1/2 years old and the Flash Player version used was one of the first (the first?) that supported Vector at all. The results of this tests are NOT VALID! any more. In general the tests are not completly wrong, but they do not fit into real-world scenarios.

Update

I have replaced the Sprite by an own class/object (SimpleObject with 3 public properties, x, y, z). The results are the same.

Vector vs Array

Started a little speed measurment with new Vector-type and the “old-fashioned” array. As everyone could read in the Adobe AS3 Docs, Vector should give us some advantages over Array iteration and data-access.

I have tried several test-settings and i was completely surprised by the results (in a bad way).

What i am most interested in, is fast access of objects. So i create a pool of object-references(simple sprite), one as an array and the other pool is defined as a Vector.<Sprite>.

[as]

var i:uint = 0;
var n:uint = N_TEST; ( n = 20000000)
var v:Vector.<Sprite>;
v = this.objectPoolV;

var timestamp:int = getTimer();

i = 0;
var r:Sprite;
while (i < n)
{
r = v[i];

i++;
}

result.htmlText += “<br />Result Vector Complex Operation Test: ” + (getTimer() – timestamp);

[/as]

This was my first test and the difference is noticeable (but look at n, how high it has to be for even get a small difference).

  • Vector result: 511 ms
  • Array result: 659 ms

But this is not a very commen use. So, next step was to save the reference in a locale variable and move the sprite in all 3 directions about 10px. I have done this test with and without an explicit cast.

[as]

var i:uint = 0;
var n:uint = N_TEST;
var v:Array;
var r:Sprite;
v = this.objectPoolA;

i = 0;

var timestamp:int = getTimer();
while (i < n)
{
r = v[i];
r.x += 100;
r.y += 100;
r.z += 100;

i++;
}

result.htmlText += “<br />Result Array Complex Operation Test: ” + (getTimer() – timestamp);
[/as]

This result i have never expected, array is faster!! than the vector, but why? I am only referencing to the current dataset.

  • Vector result: 5118 ms
  • Array result: 4885 ms

If i cast the array, the result is worse than without a cast.

[as] r = Sprite(v[i]); [/as]

I know, casting is expensive, but look at the results with casting.

  • Vector result: 7055 ms
  • Array result: 7126 ms

So, finally let’s have a look at the worst sample. Direct access of properties threw the Array and Vector.

[as]
var i:uint = 0;
var n:uint = N_TEST;
var v:Vector.<Sprite>;
v = this.objectPoolV;
i = 0;
var timestamp:int = getTimer();
while (i < n)
{
v[i].x += 100;
v[i].y += 100;
v[i].z += 100;
i++;
}
result.htmlText += “<br />Result Vector Complex Operation Test: ” + (getTimer() – timestamp);
[/as]

I have to reduce the N_TEST constant to 1000000, here are the results

  • Vector result: 1751 ms
  • Array result: 1631 ms

Is anyone able to confirm this results?

The complete testfile is downloadable here. (If you find a mistake, please tell me).



Flash CS3: "Edit Selected Bitmaps"-Panel

We are currently working on a bigger project with Flash CS3 and when it comes to performance/size-issues, there are many solutions, but one very simple is to reduce file-size of bitmaps and set some properties like smoothing enabled/disabled in the library.

This works great for us, but i do not understand why there is no availability for disabling/enabling same properties for a bunch of selected bitmaps. I have written some JSFL-Code to do this and made an extension of it so it is easy to install and work with (It’s a panel inside Flash CS3 with some buttons and a textfield).

How to do

  1. Download the extension.
  2. Select the bitmaps you want to edit (STRG + LMB, or LMB + Drag Over Bitmaps)
  3. Press one of the 4 Buttons (enter quality first for JPEG compressed bitmaps)

I hope you like it.



Astro is great!

Update 2

Seems, that i am not up to date, Powerflasher’s have already done an update to FDT (it works on my Macbook now, great ;) ). Now it is possible to read the new SWC-format.

Update

Another sample (based on the first, some filter effects on it)


With a little delay(busy right now, nice project in pipeline, further information in about a month or so), here is my obligatory FlashPlayer 10 sample. 50 Planes, rotating in all axes and moving randomely every 2sec. I have tried up to 400 planes(definitly not possible), but i tink 100 non-complex objects should be ok if you have to move them (don’t know if there is a great difference between Shapes and Sprites).

I think the Adobe-developers have done their job. From a designer’s perspective and for not-so-heavy-hardcore 3D (in my opinion approx. 90% of work) this is a more natural approach other than it is with the great 3D-libs like Papervision3D, Away3D, Sandy, Alternativa(.. are there more?, i know one other vector-rendering engine, but have forgotten the name by now).
But i am missing a camera3d-class and a scene3d (sure, easy to program one for yourself, but if you compare it with After Effects, it would be nice to have one for the non-developer-CS4-artists).

Feature i like most is the new Vector-datatype. I am not sure if it is a “real” datatype, it seems to me it is more like a generic(i know them from C#), would be great to have your “own” generics in AS3, but for the beginning the Vector is ok. I have not done any speed-measurements by now, but type-safe access should give us a great performance improvement and it will safe my time, because i will never ever have to cast the contents of an array or search for an type-problem.

I am still missing the private field for classes (very bad, i hate this crappy workarounds for Singelton, etc.). But if anyone from the Adobe guys read this, if you are going to implement private fields, abstract would be also a nice to have… ehm… and support for overloading methods. And i agree with Andrè Michelle var and function is only good for a typewriter’s cramp. Would be nice too, if the syntax for getter/setter could be reduced, and enum’s by the way ;) … ok stop, stop, stop

TextComponent is a great thing, i am on the search for a stable and easy-HTML/CSS solution for years, now it seems to be possible to do fine-typo on the web with Flash, great!

I am surprised how easy it is to setup and compile with mxmlc-compiler, great thing from Adobe to give it away as open-source(i knew the SDK is free before, but first time i try it on my own).

I was not able to do a project with FDT (FDT-parser did not like the new Vector-type …;( and the playerglobal.swc did not work too, any solutions out there?)

FlashDevelop works great, the sample at the beginning is written with it.

I know there are a lot of more interesting and nice aspects of the new player, but it’s time for bed now ;) .

Update

Vector is a class wit a “base type” and could be extended, so the could be used in a very similar manner like generics in C#, hope asdatastructures and other projects may get an update sooner or later @see poylgonal.de.

Note for myself: Study the documentation.

Download code from the sample here.



Die Ösis

Im Zuge der Berichterstattung zur Fußball-Europameisterschaft in den großen deutschen Tageszeitungen(allen voran FAZ und Süddeutsche) durfte man als “Ösi” (ja, ich bin einer) diverse Feststellungen über die grauslige Leistung österreichischer Fußballer, den nicht zu verstehenden Sprachschatz usw. lesen. Naja, wir sind es ja gwohnt, dass man ein bißchen auf das kleine Nachbarland hinabsieht, ein kleines Problem gibt es aber, nämlich wenn bei den ganzen aufgesetzten Beiträgen und Kommentaten, die augenscheinlich die Hass-Liebe zwischen uns und unseren Lieblingsnachbarn festigen soll, einfach Fehler passieren,

Betrifft mich eigentlich insofern nicht, aber nachdem ich jetzt schon den 3. fehlerhaften Beitrag der deutschen Presse innerhalb kürzester Zeit zu lesen bekommen habe, sehe ich mich berufen hier etwas klarzustellen.

  1. Wir Österreicher finden “Ösi” weder charmant, noch witzig, sondern einfach anmaßend und falsch. Es heißt und man spricht “Österreich” und “Österreicher” (irgendein deutscher Kollege hat ein Ö-Problem und murmelt immer etwas von Estareicher).
  2. “Wienerisch” oder der in der Bundeshauptstadt gesprochene Wiener Dialekt gilt nicht für Gesamt-Österreich. Grandioses Ergebnis eines Österreichers beim “Ösi-Quizl” in der Online-Ausgabe der FAZ, gerade mal 8 von 16 Antworten richtig, 80% Alt-Wiener-Wörter, bzw. Wörter die es gar nicht gibt.
  3. Dialektvielfalt widerspricht nicht dem Fakt, dass auch wir uns im so genannten Hoch-Deutschen artikulieren können, sprachlich und schriftlich. Ganz nebenbei, eine konservative Deutsch-Ausbildung ist anscheinend auch kein Garant für gute PISA-Resultate…
  4. I-Tüpferl-Reiten (dass war jetzt wohl gerade “österreichisch”, Übersetzung: pingelig) ist weiters kein Garant für Erfolg und ein richtiges Komma macht noch keinen Satz.
  5. Ich wünsche mir eine sinnvolle Berichterstattung, ansonsten seh ich mich gezwungen die deutschen Online-Medien als homogenes Eins zu verstehen, in der Reihenfolge Bild, FAZ, Süddeutsche.

Danke und Pfiat Eich,