OptoScript vs Action Block

Was hoping to gain some insight on this topic - is OptoScript faster than Action Block when performing something like the following function?

image
*correction to my code, I have made the elseif statement a regular if statement now.

image

These perform exactly the same function, however I have only recently started using OptoScript and I am a fan of this, however I don’t want to swap a whole heap of functionality out if it isn’t going to increase performance a whole heap. I like the action block due to debugging.

There shouldn’t be any significant performance difference - I would expect both of these to “compile” down into similar (if not the same) forth statements (elseif correction considered).

Do what works best for you.

3 Likes

Remember, the graphics have essentially no effect on the compiling of the code that actually runs.

I got curious about this today after seeing it come back up in the forum. I decided to create a test strategy with both options and compare the compiled output. When using OptoScript, the compiled output looks like this:

: 2_0
0 JUMP ;
: 2_1
1 LINE.NUM ~Primary_Scrubber_Fan_NO  ?ON IF 
2 LINE.NUM ^PrimaryScrubberFanState  TRUE@! 
3 LINE.NUM THEN 
4 LINE.NUM ~Auxiliary_Scrubber_Fan_NO  ?ON IF 
5 LINE.NUM ^AuxiliaryScrubberFanState  TRUE@! 
6 LINE.NUM THEN 
0 JUMP ;
T: T2
DUMMY
2_0
2_1
T;
&Script ' T2 SETTASK

When using action and condition blocks, it looks like this:

: 1_0
2 JUMP ;
: 1_3

1 LINE.NUM
  ^PrimaryScrubberFanState   TRUE@!
2 JUMP ;
: 1_4

1 LINE.NUM
  ^AuxiliaryScrubberFanState   TRUE@!
2 JUMP ;
: 1_1
TRUE

1 LINE.NUM
  ~Primary_Scrubber_Fan_NO   ?ON
LAND
IF -3 ELSE 0 THEN JUMP ;
: 1_2
TRUE

1 LINE.NUM
  ~Auxiliary_Scrubber_Fan_NO   ?ON
LAND
IF -3 ELSE 0 THEN JUMP ;
T: T1
DUMMY
1_0
1_3
1_4
1_1
1_2
T;
&Action ' T1 SETTASK

Because I’m not an expert in Forth code, I decided to ask the expert to explain the differences in the Forth code to me. You can see the results here: https://chatgpt.com/share/75c2f605-e74c-4675-8652-af2a52283d29. I don’t know how accurate the information from ChatGPT is, but it seems to make sense.

2 Likes

I got the engnieer that wrote the PAC Control engine to review this thread and the GPT summary.
The key is here… especially in environments where conditional checks and jumps are costly.
Opto has long ago optimized the control engine code for flow charts since that was the first iteration for more than a decade before OptoScript was added.

The engineer agrees with @philips summary,

I was more curious to see how differently the code would compile. I absolutely believe that any real-world impact on efficiency of running the compiled code would be infinitesimally small and definitely nothing that would justify refactoring code.

2 Likes