Rule Run Time Optimization

Rule Run Time Optimization

AMN3161
Advocate Advocate
342 Views
1 Reply
Message 1 of 2

Rule Run Time Optimization

AMN3161
Advocate
Advocate

Hello

 

I have a substantially long rule that runs on save to updates our BOM, works great and doesn't have any problems. I would like to have it run faster to be more efficient.

 

I will post two rules that do the same thing but I am curious which would run faster

 

If A = B Then
Do a thing
Else
Do another thing

 

or

 

If A = B Then
Run a Rule
Else
Run another Rule

 

Some quick testing says separating different If statements into their own rules seems faster but I don't want to invest the time if its not substantial. Does having less lines in a rule cause it to run faster even if some If statements don't have their conditions met?

 

So lets say a If Statement doesn't have its conditions met, does the software still go through the lines but doesn't do anything? Or does it just skip ahead to the next If statement to see if conditions are met?

 

Just trying to get a understanding how the software goes through the code

 

0 Likes
343 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Good question.

In a normal If statement, with a single test to check, if it tests to False, its only purpose in reading any further is to find the End If, so it know where to start processing again.  So, if this If...End If block tests to False, and it has either very few or a ton of lower level (things to do or check), it shouldn't make any 'noticeable' time difference.

 

There are some cases where two different 'operators' sound the same, but work differently from each other, that you may use when testing multiple things in your If...End If statements, that sometimes will stop after checking the first thing, but the other operator will read both tests, even if it may seem unnecessary.  The "And" & "AndAlso" operators are like this, and the "Or" & "OrElse" operators are like this.  When using "And" between two checks, it will check both conditions, before continuing, even if the first condition tests to False.  But when using "AndAlso" between two checks, it will start from the left, and if any condition is False, it won't even read any other checks after that.  This is useful when the second check is dependent on the first check being True for it to not throw an error, because it won't even read the second check if the first is False.  The "Or" & "OrElse" work much the same way.  When using the "Or" operator, it will always read both conditions/tests, but when using the "OrElse" operator, if the first condition/test is True, it won't bother reading the second condition/test.

I'm sure there are other scenarios like that too.  Hope this helps some.

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes