19.15 Summary

The most important point about performance is that it is important to pay attention to efficiency during the entire design and development cycle of a project. During the design phase, try to ensure that the algorithms chosen have the right asymptotic behavior and constant factors, and that it is possible to implement the needed operations efficiently. During the implementation phase, use the language constructs that most clearly express what the program is doing. Once the program is working correctly, it is then time to add type and sealing declarations, and to use metering and profiling tools to find and rewrite heavily used, slow parts of the program, in order to improve the performance.

One of the most important considerations when programming is not to worry about performance too soon. It is always more important that your design and implementation be clear and correct, first. There is no value in arriving at an answer with lightning speed, if it turns out to be the wrong answer.

In this chapter, we covered the following:

Table 19.1 Methods: flexibility versus performance.

Construct

Effects

direct method

highly optimizable
no method dispatch

sealed generic function on a sealed class

highly optimizable
not extensible by other libraries

sealed generic function on an open class

optimizable
other libraries can subclass

open generic function on an open class
in a sealed domain

highly optimizable
other libraries can add methods
other libraries can subclass

open generic function on an open class

not optimizable
methods can be added at run time
subclasses can be created at run time

Table 19.2 Type constraint: flexibility versus performance.

Construct

Effects

module constants

enforce program correctness

module variables

permit type inferencing

required parameters

required for method dispatch
permit type inferencing

optional parameters

permit type inferencing

return values

enforce program correctness
permit type inferencing

limited types

permit type inferencing
permit compact data representation

slots

permit type inferencing