Collect very slow
m ((username removed) (log details removed): Moving to Documentation namespace)
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<message>Write the content here to display this box</message>
I have occasionally been struck by extremely bad performance when it comes to the OCL Collect operator.
I have occasionally been struck by extremely bad performance when it comes to the OCL Collect operator.


Line 5: Line 6:
Consider this expression:
Consider this expression:
  Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create))
  Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create))
My intention is to create 7000 Detail-objects and put them in the variable <code>vCollectionDetails</code> that has type Collection(Detail).
My intention is to create 7000 Detail-objects and put them in the variable <code>'''<span class="col-black">vCollectionDetails</span>'''</code> that has type Collection(Detail).


But this expression is extremely slow.
But this expression is extremely slow.
Line 11: Line 12:
The main reason for the slowness is that Collect actually builds a result of all the results of the inner expression. In our case, this is a List of Lists; List of 1 detail, List of 2 details, List of 3 details...List of 6990 details etc. This is a heavy operation as 7000 thousand lists must be created and filled with 7000*7000/2 objects - I am not interested in that result. I only used the Collect operator as a convenient way to act on each.
The main reason for the slowness is that Collect actually builds a result of all the results of the inner expression. In our case, this is a List of Lists; List of 1 detail, List of 2 details, List of 3 details...List of 6990 details etc. This is a heavy operation as 7000 thousand lists must be created and filled with 7000*7000/2 objects - I am not interested in that result. I only used the Collect operator as a convenient way to act on each.


Look at [[OCLOperators foreach|foreach]] for a solution or to avoid returning the list. Instead, return something simple like this:
Look at [[Documentation:OCLOperators foreach|foreach]] for a solution or to avoid returning the list. Instead, return something simple like this:
  Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create);0)
  Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create);0)
In this case, the collect operator returns 1 list with 7000 zeros - much faster than 24 million references to 7000 Detail objects.
In this case, the collect operator returns 1 list with 7000 zeros - much faster than 24 million references to 7000 Detail objects.
[[Category:OCL]]
[[Category:OCL]]
{{Edited|July|12|2025}}

Latest revision as of 05:46, 11 February 2025

This page was created by Hans.karlsen@mdriven.net on 2018-09-18. Last edited by Stephanie@mdriven.net on 2025-02-11.

I have occasionally been struck by extremely bad performance when it comes to the OCL Collect operator.

After debugging, I concluded that the expression used was wrong compared to my intended usage and need.

Consider this expression:

Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create))

My intention is to create 7000 Detail-objects and put them in the variable vCollectionDetails that has type Collection(Detail).

But this expression is extremely slow.

The main reason for the slowness is that Collect actually builds a result of all the results of the inner expression. In our case, this is a List of Lists; List of 1 detail, List of 2 details, List of 3 details...List of 6990 details etc. This is a heavy operation as 7000 thousand lists must be created and filled with 7000*7000/2 objects - I am not interested in that result. I only used the Collect operator as a convenient way to act on each.

Look at foreach for a solution or to avoid returning the list. Instead, return something simple like this:

Sequence{0..7000}->collect(a| vCollectionDetails.add(Detail.Create);0)

In this case, the collect operator returns 1 list with 7000 zeros - much faster than 24 million references to 7000 Detail objects.