Performance of OCL queries

How to formulate OCL expressions to obtain high-performance queries

OCL is a very powerful tool in Vertec. You can query the entire Object Model without worrying too much about technical details (e.g. associations or calculating derived attributes such as the VAT amount on an invoice).

However, there is also a significant disadvantage: OCL is applied directly to the Vertec objects. For this to work, they must first be loaded into the session’s memory. The more objects and the more complex the query, the more performance it costs.  

Therefore, with every OCL expression, you should consider:

  1. Is OCL the right approach for this query? To help you answer this, see Performance-optimized access to Vertec objects.  
  2. If so, is it possible to reformulate the OCL expression to get the same result with fewer objects in the memory?

The OCL principle is:

Select as few objects as possible.

Let’s take the following OCL expression as an example:

openService->select(project.type.designation='Internal')

This expression is correct. If executed globally, it returns all open services on projects with project type "Internal".

However, it is highly inefficient, because it first loads all the open services in the system in the memory (including those that are not on internal projects), and only then filters for those on internal projects.

But we are not really interested in the services on the projects that are not internal. How could we get the same result without loading all the services?

It is important to always start where there is the least number of objects. In this case, these are the project types. If you take the type "Internal" and load the associated entries from there, only what is really needed will be loaded at the end, with the same result:

projecttype->select(designation='Internal').projects.openServices

The beauty of OCL is that you can navigate in all directions through the Model. So, if possible, you should always navigate through the object system instead of filtering lists. Don’t load a lot of objects and then narrow it down. Instead, load only the objects you need.  

For more OCL performance tips, see Performance-optimized access to Vertec objects.

Netherlands

United Kingdom