One method tells you how bad the removechild performance of as3 is.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.