| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (4 out of 4)

Using Compilation Configurations

Compilation configurations make possible an incremental improvement in the performance of your KB. Some compilation configurations are designed to work in conjunction with each other, while others can be used alone.

G2 offers several compilation configurations:

In this section we present the rationale behind using compilation configurations and their role in improving the performance of your KBs.

Stability Configurations

Use the stable- prefix configurations to declare that a portion of your KB is not subject to change, even when the KB is running. G2 consults these declarations when compiling items that refer to the stable portion of the KB.

G2 compiles references to a stable item differently than it compiles references to an item that is not stable. For stable items, G2 can assume that the name, class, and item location in the KB's workspace will not change as the KB runs. Therefore, G2 compiles the referencing item in a way that reduces the number of validation checks G2 must perform when executing or evaluating the actions, statements, or expressions that refer to the stable item.

Declaring the Configurations

An item can fall within the scope of configurations declared in other items that are higher in the KB's workspace and class hierarchies. Use the describe configuration menu choice to see all configurations that apply to an item.

You declare an item to be stable or not by including one or more of these configuration statements in the item's Item-configuration or Instance-configuration attributes:

See Configuring Properties of Items for an introduction to G2's configurations features and for the complete syntax of the declare properties ... as follows configuration statement.

Understanding Compiled Attributes

In general, G2 compiles each item attribute that can contain an expression, an action, or a statement. These are called compiled attributes.

When a compiled attribute contains an action or statement, G2 can invoke that attribute's contents, such as the text of a procedure or rule. When a compiled attribute contains an expression, G2 can evaluate or reference the attribute's contents, such as the Formula of a variable or the Expression-to-display of a readout-table.


Note: If you change a compiled attribute's value using the Text Editor, G2 recompiles that attribute after you direct G2 to save the attribute's edited text. If you make a valid change to a compiled attribute's value using a change the text of or conclude action, G2 automatically recompiles the attribute.

Validating References at Run-Time

The contents of a running KB are always subject to change. Therefore, when G2 compiles an attribute that refers to another item, G2 does not, by default, record any assumptions about the referenced item, such as whether that item actually exists or whether it is of a certain class.

Instead, by default, G2 compiles such an attribute to include run-time validation instructions. When that compiled attribute is invoked, evaluated, or referenced, the attribute's run-time validation instructions cause G2 to verify whether the attribute's own assumptions about the referenced item (its name, class, etc.) are still true.

To illustrate, consider the rule dependent-rule, shown in the following figure. The text of dependent-rule refers to a user-defined object named first-vehicle, whose class is vehicle, a user-defined procedure named update-tracked-vehicle-routes, and a user-defined object named current-checkpoint, whose class is CHECKPOINT:


By default, when G2 compiles this rule's text, G2 does not assume that first-vehicle, update-tracked-vehicle-routes, and current-checkpoint exist. (Even if, for example, first-vehicle does exist at the time that G2 compiles this rule, the item might cease to exist, or its class's class inheritance path might change, before your KB next invokes the rule.) Therefore, in the rule's compiled instructions G2 includes run-time validation instructions.

In this case, before G2 allows the rule to be invoked, the rule's run-time validation instructions verify the following:

On the other hand, when G2 compiles this rule's text, if G2 can assume the items referenced by name do exist, then G2 can avoid including the run-time validation instructions that the rule's references require.

To apply this idea to your KB as a whole: the more items whose compiled attributes can avoid including run-time validation instructions, the greater the potential for an incremental improvement in your KB's performance.

Understanding Compilation Dependencies

An item with a compiled attribute whose text refers to another item has a compilation dependency relationship to that other item. When G2 compiles an attribute, it automatically identifies and maintains any compilation dependency relationships between the compiled item and the item (or items) that its compiled attributes reference.

To illustrate, dependent-rule's antecedent refers to the item first-vehicle. Due to this reference, for your KB to invoke this rule without error requires that an item named first-vehicle exists in the KB, that first-vehicle's class is VEHICLE, and that the VEHICLE class maintain the same direct superior classes and direct subclasses that it has at the time dependent-rule is compiled.

These requirements represent a compilation dependency between the rule and first-vehicle. The diagram in the following figure represents this relationship graphically:


Likewise, dependent-rule has compilation dependencies on the existence of current-checkpoint and update-tracked-vehicle-routes.

When compiling an attribute, G2 can identify the compilation dependency relationships shown in the following table:

Reference that Causes Compilation Dependency Compiled item depends on...
Refer to an item by name
The existence of the named item
Refer to an item's type
The named item being of a particular type specification
Refer to an item's class
The named item being of a particular class
Invoke a procedure (or remote-procedure) by name using a start action or call statement
The existence of the named procedure (or remote-procedure) and on the types and number of its arguments and return values
Refer to a class as being a subclass of another class
One class being a subclass of another
Refer to a class as not being the subclass of another class
One class not being a subclass of another

You can make changes to stable items that do not affect those characteristics, such as concluding values into attributes, establishing relation instances, or storing items in lists.

Declaring Procedures and Methods as Inlineable

The inlineable configuration is applicable to:

When procedures and methods are declared as inlineable, they exist as separate items, but are compiled as part of the method or procedure code from which they are called. Inlining can improve performance by:

When declaring a procedure as inlineable, you must also declare it to be stable-for-dependent-compilations.

When declaring a method as inlineable, you must also declare it to be stable-hierarchy and stable-for-dependent-compilations.

Recompilation Considerations

After configuring a procedure or method as inlineable, and making it stable with its other required configuration statements, you must manually recompile both the inlineable item and the procedure or method that calls it. G2 does not present a recompilation dialog, though a message about recompiling is added to the Notes of the procedure or method.

By recompiling the calling procedure or method, G2 compiles the inlined code as part of the calling code. Since inlined procedures and methods are compiled in their calling procedure, they do not require a procedure invocation at run time, and performance improves.

Editing an existing inlined procedure or method causes G2 to display a dialog indicating that the item is stable and editing could make recompilation necessary.

Declaring Items as Stable-Hierarchy

The stable-hierarchy configuration is applicable to:

Declaring an item as stable-hierarchy indicates that neither the class hierarchy of the method, nor the class associated with a method will be changed in any way.

Declaring a method as stable-hierarchy also implies that the return value types and the number and type of method arguments will not change.

When you declare an item as stable-hierarchy, G2 can complete optimizations, including inlining, only if these conditions are met:

  1. The method or method-declaration is configured as stable-hierarchy.

  2. In the calling procedure or method, the class for which the method is called (the first argument of the method) has no subclass that defines a method of the same name with the same number of arguments.

    For example, if there is a fill method whose first argument is vessel, for optimization to occur, the class vessel could not have a subclass that defined a fill method with the same number of arguments. At run time, such a method hierarchy would make it impossible for G2 to know which method was actually being called, since the vessel class passed to the fill method could be either vessel or one of its subclasses.

Declaring Items Stable-for-Dependent-Compilations

You apply a stable-for-dependent-compilations configuration to an item upon which other items have a compilation dependency. If the item is an instance of a user-defined class, then for G2 to consider that item as stable, you must also apply a stable-for-dependent-compilations item configuration to the definition item for its class.


Note: After applying a stable-for-dependent-compilations configuration to a set of items, use the Inspect facility to recompile your entire KB. Until you do so, your KB's performance cannot take advantage of the newly declared item stability.

In our example, if you apply a stable-for-dependent-compilations configuration on first-vehicle then recompile your KB, the compiled attributes in dependent-rule that have a compilation dependency upon first-vehicle no longer include instructions that check, for instance, whether first-vehicle exists. This helps dependent-rule execute more quickly than it could before first-vehicle was configured stable-for-dependent-compilations.

Identifying Potential Performance Improvements

To gain the greatest potential performance improvements in your KB, we recommend that you take this approach:

  1. Configure the entire KB as stable-for-dependent-compilations. To do so, include a declare properties as follows : stable-for-dependent-compilations statement in the Item-configuration attribute of each top-level workspace in your KB. (This approach is especially preferred for modular KBs.)

  2. Configure each workspace subhierarchy containing items whose knowledge can change as the KB runs as not being stable. You do this by including a declare properties as follows : not stable-for-dependent-compilations statement in the Item-configuration attribute of the workspace representing each subhierarchy of items that is subject to change.

To take this approach, you must organize the workspaces in your KB's workspace hierarchy so that some workspace hierarchies are designed to remain stable during your KB development project, while other regions are designed to contain transient items and other items whose knowledge is subject to change as the KB runs. The following figure illustrates this approach:


This Inspect workspace shows the workspace hierarchy for a simple KB that contains five workspaces. The items located in the DEVELOPMENT-UTILITIES-WORKSPACE and CLASSES-WORKSPACE workspaces contain items that represent the KB's stable knowledge (items whose definitional characteristics don't change as the KB runs).

On the other hand, the GLOBAL-SCHEMATIC-VIEW-WORKSPACE and ZOOM-SCHEMATIC-VIEW-WORKSPACE workspaces contain items that represent the KB's dynamic knowledge (the items whose knowledge is expected to change as the KB runs).

For this sample KB, after configuring the entire KB as stable-for-dependent-compilations, you would configure only the GLOBAL-SCHEMATIC-VIEW-WORKSPACE and ZOOM-SCHEMATIC-VIEW-WORKSPACE workspaces as not stable-for-dependent-compilations.

If you choose not take this approach, the following principles determine the potential performance improvement for your KB:

Identifying Knowledge that is Not Eligible for Performance Improvements

Some aspects of your KB's processing are not subject to performance improvements based on declaring item stability:

Understanding Guidelines for Configuring Groups of Items

Keep the following guidelines in mind before adding a stable-for-dependent-compilations configuration that has a wide scope:

Understanding Guidelines for Configuring Items in a Modular KB

In a modular KB, items in a required module should not have compilation dependences upon items (such as definitions) in a requiring module. In general, do not declare compilation configurations based upon compilation dependencies that run contrary to the KB's module dependencies.

Declaring Items Independent-for-All-Compilations

When G2 compiles any attribute in an item declared as independent-for-all-compilations, G2 does not compile the item to take advantage of compilation dependencies upon any other items declared as stable-for-dependent-compilations. Declaring an item independent-for-all-compilations affects that item's compilation only if the item's compiled attributes reference other items. In general, only use this option if you don't trust stable configured items to remain stable, probably a rare occurrence.

For example, if a compiled attribute in item A depends upon other items, one of which (item B) is configured as stable-for-dependent-compilations, then you can declare item A as independent-for-all-compilations. This causes G2 to compile item A without taking advantage of any optimizations due to its dependency on item B.


Note: You do not gain any potential improvement in your KB's performance when you configure items as independent-for-all-compilations. Rather, use this configuration to isolate an item from requiring a recompilation whenever another item, upon which it depends, changes its name, its class, and so on.

For an item that has compilation dependencies on other items, configuring that item as independent-for-all-compilations allows you to choose when that item is next recompiled. This can be preferable in the following two situations.

Isolating a Group of Items From Automatic Recompilation

Assume that you have created an item, such as a procedure, that has compilation dependencies on a few other items, such as other procedures and functions, and those other items will change often as you develop your KB. Assume also that many other items depend upon your item, such as more general-purpose procedures and functions that must call your procedure. In this case, by configuring your procedure as independent-for-all-compilations, you can prevent your procedure from being subject to automatic recompilation due to changes in an item upon which it depends.

Further, because other items in your KB depend upon your procedure, you can also configure it as stable-for-dependent-compilations.

Isolating a Group of Items from Items Provided by Other Developers

In a modular KB that directly requires a proprietary modular KB provided by other G2 developers, assume that you have created a procedure that has compilation dependencies upon other procedures and functions in the provided modular KB. If the next version of the provided modular KB contains a change in the procedures and functions that your procedure depends upon, you must recompile your procedure, as well any other items in your modular KB that depend upon your procedure.

To manage the activity of recompiling items in your own modular KB that depend on items in other modular KBs that you do not control, declare as independent-for-all-compilations all items in your modular KB that depend upon items in the provided KB.

Changing Items that Have Compilation Configurations

As items change during your KB's processing, the compilation dependency relationships declared among the KB's items can also change. This section describes the kinds of changes to compilation dependencies that G2 recognizes and how the dependencies themselves are changed.

After Deleting an Item Declared Stable-for-dependent-compilations

The most drastic change to a stable item is to delete it. When you interactively delete an item declared as stable-for-dependent-compilations, G2 first displays a confirmation dialog. For instance, if deleting a definition item whose instances are within the scope of a stable-for-dependent-compilations configuration, G2 displays this dialog:


If your KB's processing deletes stables items programmatically, G2 does not prompt for confirmation.

After G2 deletes an item that is within the scope of a stable-for-dependent-compilations configuration, G2 removes the compilation dependency relationships between the deleted item and its dependent items.

After Changing the Knowledge of Items Declared Stable-for-dependent-compilations

For items that depend on an item declared stable-for-dependent-compilations, G2 compiles those items with the assumption that the following knowledge will not change:

Therefore, G2 prevents a KB's processing from performing the following actions on items declared stable-for-dependent-compilations:

If your KB performs one of these actions programmatically, G2 denies the attempt and signals an error. A sample Operator Logbook error message appears next.


If you interactively edit a compiled attribute of an item declared stable-for-dependent-compilations, G2 displays the following dialog:


Press OK to enter the Text Editor. Press Cancel to rescind your attempt to edit the attribute.

When you finish editing the compiled attribute in the Text Editor, G2 compiles the attribute, then checks whether any compilation dependency relationships with dependent items are affected by the edit. For each dependent item whose compilation dependency is affected, G2 changes its OK/incomplete/bad status to incomplete. Before G2 can again use the affected item in your KB's processing, you must recompile the item so that its compilation status (shown in the item's Notes attribute) is again OK.

After Removing a Stable-for-dependent-compilations Configuration

Assume that your KB contains an item declared stable-for-dependent-compilations, and contains other items, each with its own compilation dependency relationship with the stable item. Further, assume that the dependent items have been compiled to take advantage of their dependency on the stable item.

Given these assumptions, if you remove the declare properties ... as follows : stable-for-dependent-compilations configuration statement from the stable item, you break the compilation dependencies among the KB's items. Therefore, after you remove a stable-for-dependent-compilations configuration from an item, G2 sets the OK/incomplete/bad status of the dependent items to incomplete. G2 also displays the dialog shown next:



Tip: Your KB's processing cannot use items whose OK/incomplete/bad status is incomplete until they are successfully recompiled.

After Changing an Unconfigured Dependent Item to an Independent Item

For an item that has a compilation dependency on another item, but is not itself subject to any compilation configuration, G2 recognizes the following ways to change the item's compilation status:

Performing any of these operations causes G2 to set the item's OK/incomplete/bad status to incomplete, then displays the following dialog that initiates a recompilation of all items with incomplete status in the KB:


| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (4 out of 4)

Copyright © 1997 Gensym Corporation, Inc.