Locality of reference
Keep the instructions processed and data used in a program within a relatively small number of pages (4096 byte segments). This quality in a program is known as locality of reference.
About this task
You can do this by:
- Making the execution of the program as linear as possible.
- Keeping any subroutines that you use in the normal execution sequence as close as possible to the code that invokes them.
- Placing code inline, even if you have to repeat it, if you have a short subroutine that is called from only a few places.
- Separating error handling and other infrequently processed code from the main flow of the program.
- Separating data used by such code from data used in normal execution.
- Defining data items (especially arrays and other large structures) in the order in which they are referred to.
- Defining the elements in a data structure in the approximate order in which they are referred to. For example, in PL/I, all the elements of one row are stored, then the next row, and so on. Define an array so that you can process it by row rather than by column.
- Initializing data as close as possible to where it is first used.
- Avoiding COBOL variable MOVE operations, because these expand into subroutine calls.
- Issuing as few GETMAIN commands as possible. It is better for the program to add up its requirements and do one GETMAIN command than to do several smaller ones, unless the durations of these requirements vary greatly.
- Avoiding use of the INITIMG option on a GETMAIN command, if possible. It causes an immediate page reference to the storage that is obtained, which might otherwise not occur until much later in the program, when there are other references to the same area.
Note: Some of the previous suggestions can conflict with
your installation's programming standards if these are aimed at the
readability and maintainability of the code, rather than speed of
execution in a virtual storage environment. Some structured
programming
methods, in particular modular programming techniques, make extensive
use of the PERFORM command in COBOL (and the equivalent programming
techniques in C, PL/I, and assembler language) to make the structure
of the program clear. This can also result in more exceptions to
sequential
processing than are found in a nonstructured program. Nevertheless,
the much greater productivity associated with structured code can
be worth the possible loss of locality of reference.