Fall_X
07-24-2006, 07:26 PM
Not sure if anyone is interested, but I just wanted to share this... It's pretty obvious, but hey, it might be useful to some.
I was parsing a rather large XML-file (6398 lines), and it took about 2000ms to complete, which was not really acceptable. The problem was, I was looping through a nodelist, and every iteration I did this :
var tile:XML=xmlMap.layer[3].data.tile[index];
I found out that exactly that line was causing the slowness, because I commented everything that happened before or after it, and it was still slow, however, if I also commented that line, execution was instant. So before the loop, I did this :
var tiles:XMLList=xmlMap.layer[3].data.tile;
And in the loop, I changed it to
var tile:XML=tiles[index];
Now, it seems logical that it would fasten it up a bit, but this tiny modification changed the execution from over 2000ms to 63ms, so that was pretty amazing.
The reason why it's that much faster is that when I did xmlMap.layer[3].data.tile[index], Flash would have to deal with the entire xml-file each time, scanning through the tree to find my data.
By making some more variables like that, I managed to get the execution time down to 31ms.
So, my advice is : always make seperate variables for XML nodes and XMLLists. It makes a world of difference, especially when working with large files. Going from 2000ms to 31ms to parse something is pretty good if you ask me.
I was parsing a rather large XML-file (6398 lines), and it took about 2000ms to complete, which was not really acceptable. The problem was, I was looping through a nodelist, and every iteration I did this :
var tile:XML=xmlMap.layer[3].data.tile[index];
I found out that exactly that line was causing the slowness, because I commented everything that happened before or after it, and it was still slow, however, if I also commented that line, execution was instant. So before the loop, I did this :
var tiles:XMLList=xmlMap.layer[3].data.tile;
And in the loop, I changed it to
var tile:XML=tiles[index];
Now, it seems logical that it would fasten it up a bit, but this tiny modification changed the execution from over 2000ms to 63ms, so that was pretty amazing.
The reason why it's that much faster is that when I did xmlMap.layer[3].data.tile[index], Flash would have to deal with the entire xml-file each time, scanning through the tree to find my data.
By making some more variables like that, I managed to get the execution time down to 31ms.
So, my advice is : always make seperate variables for XML nodes and XMLLists. It makes a world of difference, especially when working with large files. Going from 2000ms to 31ms to parse something is pretty good if you ask me.