[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8. How to Build Efficient ASIS Applications

This chapter identifies some potential performance issues with ASIS applications and offers some advice on how to address these issues.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1 Tree Swapping as a Performance Issue

If an ASIS Context comprises more then one tree, then ASIS may need to switch between different trees during an ASIS application run. Switching between trees may require ASIS to repeatedly read in the same set of trees, and this may slow down an application considerably.

Basically, there are two causes for tree swapping:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2 Queries That Can Cause Tree Swapping

In ASIS-for-GNAT, tree swapping can currently take place only when processing queries defined in:

 
Asis.Elements
Asis.Declarations
Asis.Definitions
Asis.Statements
Asis.Clauses
Asis.Expressions
Asis.Text

but not for those queries in the above packages that return enumeration or boolean results.

For any instantiation of Asis.Iterator.Traverse_Element, the traversal itself can cause at most one tree read to get the tree appropriate for processing the Element to be traversed, but procedures provided as actuals for Pre_Operation and Post_Operation may cause additional tree swappings.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.3 How to Avoid Unnecessary Tree Swapping

To speed up your application, try to avoid unnecessary tree swapping. The following guidelines may help:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.4 Using gnatmake to Create Tree Files

To create a suitable set of tree files, you may use gnatmake. GNAT creates an ‘ALI’ file for every successful compilation, whether or not code has been generated. Therefore, it is possible to run gnatmake with the ‘-gnatct’ option; this will create the set of tree files for all the compilation units needed in the resulting program. Below we will use gnatmake to create a set of tree files for a complete Ada program (partition). You may adapt this approach to an incomplete program or to a partition without a main subprogram, applying gnatmake to some of its components.

Using gnatmake for creating tree files has another advantage: it will keep tree files consistent among themselves and with the sources.

There are two different ways to use gnatmake to create a set of tree files.

First, suppose you have object, ‘ALI’ and tree files for your program in the same directory, and ‘main_subprogram.adb’ contains the body of the main subprogram. If you run gnatmake as

 
$ gnatmake -f -c -gnatct ... main_subprogram.adb

this will create the trees representing the full program for which main_subprogram is the main procedure. The trees will be created “from scratch”; that is, if some tree files already exist, they will be recreated. This is because gnatmake is being called with the ‘-f’ option (which means “force recompilation”). Usng gnatmake without the ‘-f’ option for creating tree files is not reliable if your tree files are in the same directory as the object files, because object and tree files “share” the same set of ‘ALI’ files. If the object files exist and are consistent with the ‘ALI’ and source files, the source will not be recompiled for creating a tree file unless the ‘-f’ option is set.

A different approach is to combine the tree files and the associated ‘ALI’ files in a separate directory, and to use this directory only for keeping the tree files and maintaining their consistency with source files. Thus, the object files and their associated ‘ALI’ files should be in another directory. In this case, by invoking gnatmake through:

 
$ gnatmake -c -gnatct ... main_subprogram.adb

(that is, without forcing recompilation) you will still obtain a full and consistent set of tree files representing your program, but in this case the existing tree files will be reused.

See the next chapter for specific details related to Ada compilation units belonging to precompiled Ada libraries.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root on March 13, 2014 using texi2html 1.82.