CATEGORY


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>.


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);

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.


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);
 

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.

 r = Sprite(v[i]); 

I know, casting is expensive, but look at the results with casting.
<ul>
<li>Vector result: 7055 ms</li>
<li>Array result: 7126 ms</li>
</ul>
So, finally let’s have a look at the worst sample. Direct access of properties threw the Array and Vector.

 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);
 

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).



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.



Steve Jobs and Flash

As i read statements from Steve Jobs about Flash Lite and Flash yesterday and that it will be not supported on the iPhone or iPod Touch i have to shake my head. I have always thought that Jobs is a technological and design visionary in his field.

But maybe he has a little Flash-phobia?

I read about a statement, where Steve Jobs said, he did not understand why YouTube is supporting Flash and not Quicktime. As we all know, for the users, the popularity of video on the web is not depending on which player we publish for, it demands on quality and simplicity of the environment. The major advantage of Flash-Video-Web i can see, is the fully customizeable UI, the seamless integration into the browser and maybe the most important, it simply works.

In the past 2 years i have bought nearly every iPod, Apple was selling, because for me the iPod stands for great design, simplicity and lifestyle and last but not least, the greatest UI ever seen. But what is about the software you need to work with. To call by name, i am talking about iTunes and QuickTime.

If you are a heavy user of both worlds(Windows and Mac based PC’s) like me, you can’t ignore the diffent product politics of both. Everyone berates Microsoft for their closed environment by design strategy. But have a look at Apple’s most popular tools. iTunes is simply annoying. On my 1 year old PC(Dual Core 2,4GHz with 4GB of RAM) iTunes is so slow, that i never want to listen music with it and because i use a x64 Windows system(XP Prof) my iPod Touch will never synchronize with my library.

Isn’t this annoying?

I want to work with my PC AND have some media on it and not to have to make a decision between one or the other. Next problem is QuickTime, for sure, everyone in the media branch supports quicktime for interoperability, but have a closer look at what some agencies do. They are publishing QuickTime showreels on the web, even non-optimized ones.
As a windows-user you get a 50% chance of a browser-error (especially with FireFox). Is this ok? I think it’s not and it goes as far as i try to skip every page where this creepy QuickTime logo appears.

For my point of view, this kind of logo representation during the initialization process(which tooks terribly long for Java and QuickTime, browser freezes and so on) was always a reason why Flash RIA’s looked more seamless to me.

If i would know it better, i would say, Steve is a little bit pissed that he is not the inventor of the most popular and advanced interactive-platform-solution of the 21. century. As everyone could read in the news, at least 30% of all iPhones are cracked. For me it’s clear, people want to have the freedom about which applications are on their Micro-PC’s. I would recommend Steve to open the iPhone and iPod touch for developers and integrate a Flash-plugin into the great Safari Browser. iPod touch is the first mobile-device i really use to surf the web and if it supports flash, i promise, their will be developed some great applications for it.

Steve and Apple should not depreciate the Windows world, we love your great devices and want to get the max out of it.



It's MAX time

If someone believes this is a corresponding post to this, no it’s not. MAX is the Adobe conference and there are some updates out there.

“Codename ASTRO” (new Flash Player) will support simple 3D effects(nothing similiar to Paperviersion i think), some enhanced text layout components and last but not least, support for GPU rendering. What does this mean, that in near future everyone is able to create a new HalfLife based on the Flash Platform.

No.

It means that Adobe is going to get the most out of our systems so that every content will run smooth even on CPU’s with less power. GPU’s are very powerful today and most of them implements OpenGL specification. There is a new project on Adobe Labs, called Hydra. Hydra is part of the “Adobe Image Foundation Toolkit” and will be a powerful, C-similiar programing language to create native effects and blendmodes.

No Worries for those who haven’t a compatible graphics card, there will be a software rendering mode too.

Welcome to the future (*hint*).



AS3 and Open Source

Seit über einem Jahr gibt es nun die Spezifikation für ActionScript 3 und einen lauffähigen Compiler. Zeit, mal ein paar Änderungen in dem Open Source Verhalten der Flash Community aufzuzeigen. Ich kann mich noch erinnern, als vor ca. 2 Jahren jemand über die Unfähigkeit von Flash Programmierern gejammert hat, Open Source im Team oder überhaupt zu produzieren und es aber auch einzusetzen. ActionScript 2 war wohl noch zu unausgegoren um große Frameworks wirklich in den Köpfen der Entwickler zu positionieren.

Anders sieht es heute aus, folgende OpenSource Projekte haben wohl einiges verändert und die Professionalität steigt immer weiter.

Popforge – Sound

Wiiflash

Papervision

Und natürlich viele weitere Projekte auf osflash.org. Das bemerkenswerte ist aber weiters, dass die Spezialagenturen erkennen wie wichtig der Austausch untereinander geworden ist. Es wird nicht mehr still hineinentwickelt, sondern die Ergebnisse werden ausgetauscht, werden dadurch auch sauberer und die Qualität der gesamten Flash Platform steigt in den Augen der Betrachter. Aktuellstes Beispiel, die Audi Rythm of Lines Site. Basiert auf Papervision und ist in seiner Umsetzung ein koch komplexes Stück Software.



BMW:Dick

BMW
Sehr, sehr, sehr dick das Ganze, alleine wegen dem Teil sollte jeder BMW Fahrer 5 Brusthaare mehr haben, und ich traue mich zu wetten, teurer, viel teurer als jeder Durchschnittsspot.

http://www.pursuitacrosseurope.com/pace/

Technisch haben ist hier einiges gelöst worden, dass mir vor 2 Jahren noch versagt geblieben ist. So finde ich die Umgebung mit den Strommasten und den Linien sehr gut, Auflösung und Farbe lassen sich performancemäßig gut kombinieren, allerdings sind die Leiden der Mode7 Engine auch hier zu erkennen. Hässliche Pixeltreppen und zu geringe Qualität auf Grund der immens hohen Rechnerbelastung. Der Horizont könnte auch mal getweaked werden, aber die Kameraintegration ist sehr gut gelungen, Soundsteuerung ebenso. Alles in allem ziemlich rund und die 3D Einführungen sind Hammer.




© 2006 - 2012 Hannes Wolfgang Moser