Optimization of code for port connections
IBM® Engineering Systems Design Rhapsody® includes an option to optimize the code generated for port connections. In many scenarios, this can result in improved performance of your application.
When ports are used in models, there are often situations where achain of nonbehavioral ports is connected to each other, with calls being delegated from one end to the other. This results in poorer runtime performance and also makes debugging the application more difficult.
To prevent this problem, you can use the port connection optimization feature. When you use this code generation option, the generated code is designed to connect the ports at either end of this chain at run time.
When deciding whether to use the connection optimization feature for ports, take into account that there is a tradeoff. The optimized code results in improved performance, but also uses more memory temporarily when the application starts and the ports are initialized.
When using this optimization feature, code is not optimized for connections involving the following types of ports:
- Rapid ports
- Multicasting ports
- Ports with required interfaces that contain only event receptions.
- Ports with provided interfaces that contain at least one event (or are derived from classes with at least one event)
Use of port connection optimization is controlled by the following properties:
- CPP_CG::Configuration::OptimizePortConnectors - determines whether Rhapsody should generate the code that is required for optimization, in full or in part.
- CPP_CG::Port::IncludeInConnectorOptimization - determines which ports are included in the optimization when it is used.
Controlling generation of port connection optimization code
The port connection optimization code consists of:
- Infrastructure code to make the feature possible
- A call to a macro called
OM_OPTIMIZE_PORT_CONNECTORS
to actually enable the feature. This macro calls the optimization algorithm that computes and sets the destination for each port.
The OptimizePortConnectors property controls the generation of this code, providing the following possible values:
- NoOptimization—no optimization is used - neither the infrastructure code nor the call to the macro is generated
- ActivateInComponent—Rhapsody generates both the infrastructure code and the call to the macro. For executable components, the macro call is generated in the main function. For libraries, the call is generated in the constructor of the class representing the component. The call to the macro is made after all the relations have been initialized. When this value is used, optimization is enabled for ports at the component level, meaning that only links within the component are optimized.
- ActivateExternally—the required infrastructure code is generated but Rhapsody does
not generate the call to the
OM_OPTIMIZE_PORT_CONNECTORS
macro. It is user's choice to include the call to this macro in the code of a component that uses the optimized component or in other user-provided code.Note: The call to the macro frees up the extra memory that was used during port initialization. So if you use the ActivateExternally property value, but do not include a call to the macro, this memory will not be freed.
The ActivateInComponent value is appropriate for executables. For libraries, it is appropriate in situations where the components that use the library do not have to know whether port connector optimization is used or not.
The ActivateExternally value should be used in situations where cross-component connections must be optimized. It is also appropriate in situations where port connections are also initialized manually.
OM_OPTIMIZE_PORT_CONNECTORS
macro. In such cases, the extra memory that was used
during port initialization is only freed if you include your own call to the macro.Controlling which port connections are optimized
If you have set the value of the OptimizePortConnectors property to use optimization, you can control which port connections are optimized by setting the value of the Boolean property CPP_CG::Port::IncludeInConnectorOptimization.
If a chain of ports includes a port for which the value of the property is set to False, that port will not be included in the optimization, but optimization will still be used for the other port connections in the chain.
Customizing the port connection optimization code
The following properties can be used to customize the port connection optimization code, for example, the names of the macros that are used and the header files included:
- CPP_CG::Framework::PortConnectorsOptimizationBaseClassPattern
- CPP_CG::Framework::PortConnectorsOptimizationImpIncludeFiles
- CPP_CG::Framework::PortConnectorsOptimizationOptimizationPattern
- CPP_CG::Framework::PortConnectorsOptimizationRegistrationPattern
- CPP_CG::Framework::PortConnectorsOptimizationSpecIncludeFiles