LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange constant folding


@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?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 11 of 16
(1,077 Views)

@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.

0 Kudos
Message 12 of 16
(1,075 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 13 of 16
(1,070 Views)

@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.

Matt J | National Instruments | CLA
0 Kudos
Message 14 of 16
(1,063 Views)
Typically, you need to disable debugging for folding to occur.
0 Kudos
Message 15 of 16
(1,047 Views)

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.

 

0 Kudos
Message 16 of 16
(1,026 Views)