Ada 95 Quality and Style Guide | Chapter 10 |
10.7.1 Pragma Inlineguideline
When measured performance indicates, use pragma Inline when calling overhead is a significant portion of the routine's execution time. example
procedure Assign (Variable : in out Integer; Value : in Integer); pragma Inline (Assign); ... procedure Assign (Variable : in out Integer; Value : in Integer) is begin Variable := Value; end Assign;rationale
If calling overhead is a significant portion of a subprogram's execution time, then using pragma Inline may reduce execution time.
Procedure and function invocations include overhead that is unnecessary when the code involved is very small. These small routines are usually written to maintain the implementation hiding characteristics of a package. They may also simply pass their parameters unchanged to another routine. When one of these routines appears in some code that needs to run faster, either the implementation-hiding principle needs to be violated or a pragma Inline can be introduced.
The use of pragma Inline does have its disadvantages. It can create compilation dependencies on the body; that is, when the specification uses a pragma Inline, both the specification and corresponding body may need to be compiled before the specification can be used. As updates are made to the code, a routine may become more complex (larger) and the continued use of a pragma Inline may no longer be justified.
exceptions
Although it is rare, inlining code may increase code size, which can lead to slower performance caused by additional paging. A pragma Inline may actually thwart a compiler's attempt to use some other optimization technique, such as register optimization.
When a compiler is already doing a good job of selecting routines to be inlined, the pragma may accomplish little, if any, improvement in execution speed.
< Previous Page | Search | Contents | Index | Next Page > |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC |
Appendix | References | Bibliography |