CPU usage with Flex Performance Optimization

Source: Internet
Author: User
CPU usage with Flex Performance Optimization

First, I would like to say a few words. There is a project in the team that is being tested. Recently, it was called back by the customer. The problem lies in the performance of flex. The symptoms are as follows. When the as service layer calls the background Java Servlet, the UI will pop up a repeated loading animation. The callback function will parse the data and re-paint the UI. This is a widely used method for processing loading + asynchronous clients. But the problem is that when the callback function is executed, the animation that should have been repeatedly executed has paused (it takes 6 seconds to call and display the animation, the pause may take 3 seconds), and the loading time is too long, seriously affecting the customer experience.

 

To solve this problem, many detours were taken, and some possible causes were ruled out one by one, but the problem still could not be found. Fortunately, at the tip of a group of friends flying master, the problem was determined that the CPU usage in the browser was too high, causing the browser to be suspended. I hope to help you with troubleshooting and solutions.

1. Because the CPU usage is too high, there is no doubt thatCodeSo start the flex profile tool that has never been used to find the culprit method.

Select the app you want to detect and switch to the profile view.

This dialog box allows you to select the monitoring method. The above is the memory usage, and the following is the performance (the execution time)

Click.

Double-click performance profile to list all functions executed during initialization.

Finding the method you write the most time-consuming is our goal (it is already optimized. A previous method took about ms)

Let's look at the code! It turns out that a two-layer for loop is a ghost. These two loops traverse the server to return data and assemble them into as3 VO objects. There are thousands of new objects. It is strange that the CPU usage does not exceed the limit.

Solution: as3 does not have a thread concept, so it cannot make the for loop run again and sleep () makes cup breathe, therefore, we need to use the Timer class to help us implement the CPU breathing function.

You should be clear about the use of the Timer class by checking the API. New timer (Execution interval, number of executions ). We can change the first layer of for loop to a timer operation. The number of executions is the length of for, and the execution interval is the time you want to breathe the CPU. Then we can set some variables to static to replace our first for loop function.

OK. After the optimization is completed and tested, the CPU usage is reduced, and the animation does not produce a significant pause, and the profile is used for monitoring, we found that this step was reduced from 1800 ms to 800 ms, and saved 1 second. (it may be because the CPU is reduced, but the execution efficiency is high)

You can also use this idea when handling large background data in your project. If you have a better solution, I hope to share it with you.

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.