SFSArray bad performance

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

jamieyg3
Posts: 84
Joined: 25 Sep 2008, 16:01

SFSArray bad performance

Postby jamieyg3 » 03 Nov 2011, 21:34

I'm trying to check if a value is contained inside an array....
With a SFSArray, on my slow-ish laptop, this code takes 374968ms!! That's over 6 minutes!

Code: Select all

var arr:ISFSArray=new SFSArray();
for(var i:int=0; i< 30000; i++)
    arr.addInt(i);
arr.contains(25000); //this line takes 6 mins


Compare it to this as3 Array, which takes 0ms or 1ms!

Code: Select all

var arr2:Array=new Array();
for(var j:int=0; j<30000; j++)
    arr2.push(j);
arr2.indexOf(25000); //this line takes 0ms, sometimes 1ms
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 Nov 2011, 14:44

Yes it is possible.
I tested on a dual core laptop and, to avoid the Flash 15 seconds timeout, I searched for 10000 instead of 30000

It takes ~6 seconds. The reason is that each value is wrapped in a object and we can't use the native indexOf function of the Array class, we must use a for loop which brings linear ( O(n) ) performance. In other words the higher the index of the element, the longer it will take to reach it and find it.

Unfortunately it seems that Flash sucks big time at this because the same exact test done on the server side scores a mere 11 milliseconds, which is a whole different story :)

It's also true that scenarios in which you have 30 thousand elements to be transmitted from server to client or viceversa should be very rare and probably should be avoided at all costs :)
Lapo
--
gotoAndPlay()
...addicted to flash games
Rotty956
Posts: 74
Joined: 02 Jan 2011, 15:58

Postby Rotty956 » 15 Nov 2011, 15:53

I think if you send a list like that should consider pagination. I would be surprised if the user could mentally process 30000 different things at once.

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 42 guests