| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (11 out of 12)

Inlining a Method

A method declared as inlineable exists as a separate item, but is compiled as part of the calling code when called from another method or procedure. Inlining a method can improve performance by:

However, inlined methods increase the size of the executable code, because the method code is copied redundantly to every point from which it is invoked. Inlining is best for small methods that are called frequently, typically from a loop that iterates many times.

Embedded code is incompatible with asynchronous and recursive invocation, so the code for an inlineable method is actually inlined only for a nonrecursive call. Inlineable methods exist as ordinary items; starts and recursive calls to them are handled just as if the method were not inlineable.

Declaring a Method as Inlineable

Declaring a method as inlineable requires the additional stable-hierarchy and the stable-for-dependent-compilation configuration.

Declaring a method as stable-hierarchy implies that a more specialized method will not be added below the current method in the method hierarchy. If the method includes any return values, the stable-hierarchy declaration additionally guarantees the return value types.

To declare that a method be inlined:


Tip: As with other configurations, the configuration statements stable-hierarchy and stable-for-dependent-compilation can be applied to a workspace. Whenever configurations are applied to a workspace, their effects propagate to every applicable item (methods in this case) upon the workspace, and all item subworkspaces.

Recompiling an Inlineable Method

When you change the Item-configuration of a method to include these properties, the Notes attribute of the method changes to read:

To recompile the inlineable method:

  1. Choose edit from the table item menu of the method attribute table. G2 displays this dialog, because the method has been declared as stable:


  2. Click OK to continue.

  3. Save the edited method to recompile it. The method Notes status will be OK.


Note: After making a method inlineable and recompiling it, other methods and procedures that call the inlined method must be recompiled to incorporate the inlineable code. You can recompile a single procedure method by editing it in the Text Editor and saving any changes, or recompile your entire KB using Inspect.

Testing for an Inlined Method

You can test whether a method has been inlined through the G2 Tracing facility.

To test for an inlined method:

  1. In the Debugging Parameters system table, change the Tracing-and-breakpoints-enabled? attribute to yes.

  2. Change the value of the Tracing-message-level attribute to:

  3. Run the procedure that calls the inlined method. If the inlined code has been incorporated into the calling procedure, the inlined method will not appear in the trace messages.

For a further discussion on using the inlineable and stable-hierarchy configurations, see Using Compilation Configurations.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (11 out of 12)

Copyright © 1997 Gensym Corporation, Inc.