Adobe Flex 3 Help

About profiling

The Adobe Flex profiler helps you identify performance bottlenecks and memory leaks in your applications. You launch it from within Adobe Flex Builder, and as you interact with your application, the profiler records data about the state of the application, including the number of objects, the size of those objects, the number of method calls, and the time spent in those method calls.

Profiling an application can help you understand the following about your application:

  • Call frequency In some cases, you might discover that computationally expensive methods are called more than once when multiple calls are not necessary. By identifying the most commonly called methods, you can focus your performance-tuning time on a smaller area of the application, where it will have the most impact on performance.
  • Method duration The profiler can tell you how much time was spent in a particular method, or, if the method is called multiple times, what the average amount of time spent in that method was during a profiling section. If you discover that some methods cause a performance bottleneck, you can try to optimize those methods.
  • Call stacks By tracing the call stack of a method, you can see the entire path that the application takes as it calls successive methods. This might lead you to discover that methods are being called unnecessarily.
  • Number of instances (object allocation) You might discover that the same object is being created many times, when only a specific number of instances are required. In these cases, you might consider implementing a Singleton pattern if you really require only one of those objects, or applying other techniques that reduce excessive object allocation. If the number of objects is large, but necessary, you might consider optimizing the object itself to reduce its aggregate resource and memory usage.
  • Object size If you notice that some objects are disproportionately large, you can try to optimize those objects to reduce their memory footprint. This is especially helpful if you optimize objects that are created many times in the application.
  • Garbage collection When comparing profiling snapshots, you might discover that some objects that are no longer required by the application are still "loitering," or are still stored in memory. To avoid these memory leaks, you add logic that removes any remaining references to those objects.

You should not look at profiling as only a single, discrete step in the process of developing an application. Rather, profiling should be an integral part of each step of application development. If possible, you should profile an application early and often during application development so that you can quickly identify problem areas. Profiling is an iterative process, and you gain the most benefit by profiling as often as possible.

About types of profiling

Before you use the profiler, you should decide what kind of profiling you are going to do: performance profiling or memory profiling.

Performance profiling is the process of looking for methods in your application that run slowly and can be improved. Once identified, these hot spots can be optimized to speed up execution times so that your application runs faster and responds more quickly to user interaction. You generally look for two things when doing performance profiling: a method that is called only once but takes more time to run than similar methods, or a method that may not take much time to run but is called many times. You use the performance profiling data to identify the methods that you then optimize. You might find that reducing the number of calls to a method is more effective than refactoring the code within the method.

Memory profiling is the process of examining how much memory each object or type of object is using in the application. You use the memory profiling data in several ways: to see if there are objects that are larger than necessary, to see if there are too many objects of a single type, and to identify objects that are not garbage collected (memory leaks). By using the memory profiling data, you can try to reduce the size of objects, reduce the number of objects that are created, or allow objects to be garbage collected by removing references to them.

Memory profiling can slow performance of your application because it uses much more memory than performance profiling. You should only do memory profiling when necessary.

You often do both performance profiling and memory profiling to locate the source of performance problems. You use performance profiling to identify the methods that result in excessive memory allocation and long execution times. Then, you use memory profiling to identify the memory leaks in those methods.

When you know what kind of profiling you are going to do, you can start the profiler.

Additional resources

The profiler alone does not improve the size, speed, and perceived performance of your application. After you use the profiler to identify the problem methods and classes, look at the following resources in the Flex documentation for help in improving your application: