06-21-2016 10:14 AM
@crossrulz wrote:Constant Folding is when the compiler can turn part of your code into a constant. Needless to say, that can greatly increase the performance of you code. You can have the editor show you when constant folding is happening from a setting in the Options->Block Diagram. For wires, they will look fuzzy to show constant folding. Structures show faded stripes in them.
Thanks, I always wondered what "Constant Folding" was.
Does these optimisations happen regardless of having Constant Folding enabled or not?
06-21-2016 10:20 AM - edited 06-21-2016 10:34 AM
@mikeporter wrote:
Where was that discussion at? I looked on the forum and didn't find anything.
Hi Mike, I sent you a PM yesterday.
And yes, constant folding display is an important tool for optimizing code, at least for me. Often you can rearrange code to maximize folding and thus increase performance. A quick primer can be found here.
While static folding (i.e. computing the outcome of a code fragment that only has constants as inputs and replace it with a diagram constant of the result at compile time) is well known, loop invariant code folding is highlighted similarly. For example if you place an operation inside a loop that always produces the same result, you might think you have to place it in front of the loop so it is only calculated once per call of the loop and not once per iteration, which seems like N times more work. However, most of the time the compiler is smart enough to recognize loop invariant code and calculates it once before the loop starts (see e.g. figure 10 here). It is also most important to place controls in front of tight loops. They only belong inside the loop if we expect them to change during the loop, i.e. for UI related code. If controls are placed before inner loops, they can be considered constants for the duration of the loop and folded accordingly.
The LabVIEW compiler very impressive and absolutely fantastic.
06-21-2016 10:25 AM
@RTSLVU wrote:Does these optimisations happen regardless of having Constant Folding enabled or not?
Yes they do. The option just shows you where the folding is happening.
06-21-2016 10:32 AM
@RTSLVU wrote:
Does these optimisations happen regardless of having Constant Folding enabled or not?
My understanding is that it will happen as long as debugging is disabled. You can't constant fold something with debugging enabled because you may potentially want to probe that wire or step through execution which would no longer be possible.
06-21-2016 11:18 AM
06-21-2016 12:15 PM
Jacobson wrote: My understanding is that it will happen as long as debugging is disabled.
Sorry for my duplicate post, was posting via mobile and your post did not show until I replied.