Tuesday, December 3, 2019

Using traditional for each loop in DT vs Using loop of RUF

Consider there is a scenario where there is a pagelist i.e. EmployeeList with ID's starting 1 to 5000. Given an IDyou have to find out the index of that page which matches the given criteria (for example:  ID=5000) present in pagelist (EmployeeList).

Below is a wrapper activity where we have data transform which calls logic that fetches the index matches with above criteria.

How to write this data transform : GetEmployeeWithCriteria ?

One developer has coded traditionally which iterates through the pagelist in a data transform (as shown in the below screenshot) and checks for when condition. And if meets then set the index to out parameter and exit data transform.

This does the needful and returns the index. But let us see how much time data transform execution took from tracer. It took 1.293 seconds as highlighted in below screenshot.

From performance side, this 1.293 seconds is huge for a pagelist of size 5000. And this is much common scenario in programming/designing any real-time system.

Alternative approach:

Same Data Transform can be refined by substituting "for each loop" with Rule Utility Function "IndexInPageList" with the condition. In this case we have OOTB RUF available, so using the same instead of creating new one.

Let us see how much time our data transform takes to do the needful (from tracer). And it takes 0.0980 seconds which is very less when compared to previous value.

Definitely this approach is useful in improving the performance. Bottom line is wherever possible try to use Rule Utility Funcitons if they are available OOTB to improve the performance by avoiding looping from Data Transform or activities.


In the above example:

Using traditional for each loop in DT, time taken = 1.293 seconds
Using loop of Rule Utility Function, time taken    = 0.098 seconds

In the background Rule Utility Function "IndexInPageList" also uses loop in JAVA. What makes it RUF execution so fast when compared to the traditional "for each loop" of DT ?

Feel free to answer this question. 


  1. Nice observation, good to know.
    My point of view is, the DT logic will intern prepare a java code with OOTB error handling which would have taken additional time to process the logic.
    I could be wrong... :P

  2. Hi Subbu, your line of thinking is correct. Just a trigger of thought: For DT/RUF, in Pega in the background .Java file and .class file to be generated as part of rule assembly. Once generated, then execution to be made. So now is the time taking in assembly or in executing the generated code?


HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu