In fact, I have already stepped on as3, but I didn't pay too much attention to it at that time. Recently, I replaced removechild of the project with visible = false, and found that the efficiency is improved ......
Paste the code first.
Private function testremovechild (): void {var starttime: Int = gettimer (); var count: Int = 9999; For (var I: Int = 0; I <count; I ++) {var SP: SPRITE = new sprite (); addchild (SP);} trace ("when an object is created for computing", gettimer ()-starttime, "millisecond"); starttime = gettimer (); While (this. numchildren) This. removechildat (this. numChildren-1); // while (this. numchildren) // This. removechildat (0); trace ("when object computing is removed", gettimer ()-starttime, "millisecond ");}
Output
It takes 95 milliseconds to create an object.
It takes 4317 milliseconds to remove an object.
This test is very simple, but we can see that if there are objects coming in and out in the scenario ...... Removechild consumes a CPU. Adobe hasn't completed this yet, and it doesn't blame apple for saying it's lazy.
To solve the problem of removechild's eating performance, I used visible = false + Object pool hosting. FPS is indeed improved, but the actual solution still requires Flash player10.3 ......
I found a post in the previous Forum. The original words are as follows:
"In as3, the visible of a display object outside the stage is set to false, and whether the object will be re-painted is still unclear. Therefore, it is explained that Flash Player versions earlier than 10.3 will be re-painted, and Versions later than 10.3 will not be re-painted. Please note! "
Finally, I will summarize a scheme to improve the performance, and manage it with LRU Object pool + visible = false to improve the running efficiency perfectly.
One method tells you how bad the removechild performance of as3 is.