Optimization
From oorexx
Contents |
Optimization
This section gives hints on how to optimize Rexx applications. It describes a general approach to find performance bottlenecks and gives ideas to avoid them.
When to optimize an application?
The step of optimizing an application is the last one in the cycle of software development. It should be avoided as long as possible because many optimizations tend to make the code much harder to understand and less intuitive. Also it is possible that an optimized application can not be extended anymore.
To sum up, you should only think about optimizing an application when a part is very frequently used and tends to be slow. Inside a system this mainly applies to a very limited number of core functions.
What can be optimized?
There are always several approaches to solve a problem. As there are different solutions different algorithms may be involved as well. It depends on a lot of factors incurred by the environment and the requirements. One optimization may run faster on systems that has a lot of memory available, another has to cope with limited resources. The suggestions here may improve performance in some situations, but they also may fail on situations. Thus they should be seen as hints and not as recipes.
Life Objects and garbage collection
The speed of applications is mainly depended on the number of live objects available. Each time an object is allocated it uses some memory owned by the Rexx process. When the object is freed again the memory remains allocated but can be used for new objects. Internally the garbage collector stores a list of spaces in the internal memory that are free. When objects are allocated it looks for a space that fits and assigns this space to the object. It will be removed from the free space list. Doing this a lot of times can cause memory fragmentation as live objects are never relocated. They stay at the same memory address while they exist.
Assume a case where a lot of live objects exist in a system. Due to fragmentation a lot of rather small slots exists. When a new (big) object needs to be allocated the whole long list of free slots needs to be scanned in order to find a slot that fits. This process is rather time consuming. The only way to avoid this is to have as little as possible data available in the system.
