Was hoping to gain some insight on this topic - is OptoScript faster than Action Block when performing something like the following function?
*correction to my code, I have made the elseif statement a regular if statement now.
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).
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:
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.
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.
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.
If you don’t want to lose the troubleshooting aspect of function block, then keep you scripts smaller and in separate blocks. Use all the conditional blocks you need and separate each function you want to perform into a branch flow that returns either to the loop at top or continues on back to the main logic flow.