| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 14)

Effect of Tight Typing versus Loose Typing

This test compares assignment statements, varying only the type declarations of the values or items involved. It does not use stability declarations. The test profiles the following cases:

For values, assignments from a specific value type (integer) to a general value type (value or item-or-value) are equally efficient, as is the assignment from the value type to a more specific type (integer). However, assignments from the item-or-value value type to a more specific value type (integer) carries a slight performance penalty.

For objects, assignments from more general classes (object or item-or-value) to more specific classes (test-object) carries more of a penalty. Assignments from a specific class (test-object) to the same class are slightly less efficient than specific-to-specific value assignments. Assignments from a specific class (test-object) to a more general class (object) are less efficient, but assignments to item-or-value are not because G2 never has to check if it can assign a class to an item-or-value local variable.

Thus, you should always assign local variable value types to the most specific type or the most specific class possible.

The exception to this general rule is casting, described in Effect of Subclassing, Stability, and Casting on Array References.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 14)

Copyright © 1997 Gensym Corporation, Inc.