From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiler Optimization Scenarios

Good morning,

 

I'm trying to come to a deeper understanding of how much the compiler does in the way of recognizing when BD constants are unused, or are connected to a tunnel but terminate after, and remove the "dead code" and not ever allocate memory for it. Look at the following scenarios. In which of them, if any, will the compiler remove them such that no memory allocation takes place in runtime?

 

Spoiler
FireFistRedhawk_0-1651666825636.png

 

 

 

This was spurned by our team starting down the path of HALs for all of our devices with simulation modes for all of them. And how best to ensure the child classes are always included as dependencies in the executable but without every class loading automatically, or the data from a class constant. My first attempt at the factory VI is shown, and here you will see that I do that by adding class constants in a case structure with False going to the selector. I've come to realize that in development, this loads every class, still learning. But I'm still not sure what the compiler does, if anything, to recognize that as dead code and just remove it entirely. And that led me down a more general train of thought of, if a memory allocation would take place in runtime for something like that. Appreciate any guidance on this.

Spoiler
FireFistRedhawk_2-1651667631899.png

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 1 of 8
(1,104 Views)

Fun addition: Which LabVIEW version, because it has changed in some recent versions.

0 Kudos
Message 2 of 8
(1,082 Views)

Ooooo fun stuff, we are currently on a combination of 2017 and 2020, hopefully to be fully upgraded to 2020 relatively soon.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 3 of 8
(1,077 Views)

I think the behaviour of Cases 1 and 2 changed between 2017 and 2020, but I can't find the info right now when it changed. I remember people complaining that builds were not working because more code was being eliminated than before.

Message 4 of 8
(1,072 Views)

Is it possible for you to load them dynamically at runtime? You could use PPLs for your concrete implementations and build them as PPLs. Your virtual parent class would would also need to be a PPL which all of the child classes would inherit from. Store the child classes in a known location and then load the ones you need dynamically at runtime.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 8
(1,045 Views)

Sorry I should've specified, our dev team has pretty much arrived at that exact solution you described, building the classes into PPLs and storing them on a network location, to be copied and pulled down automatically to target computers when a software needs them.

 

But that whole ordeal led me down a general rabbit hole of how the compiler treats different types of "unused" code. So that's pretty much what the intent of the post was, to get some info from people well-versed on that.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 6 of 8
(1,040 Views)

@FireFist-Redhawk wrote:

For some reason you still have debugging enabled (your second picture), which also make a difference because the compiler needs to ensure that you can probe these wires, even if they don't lead anywhere useful. Once debugging is disabled, dead code is eliminated significantly more effectively.

 

(Of course debugging also gets typically stripped out when building an executable. Sorry, I don't have anything to contribute to your "classier" problem 😄 )

Message 7 of 8
(1,020 Views)

@altenbach wrote:

@FireFist-Redhawk wrote:

For some reason you still have debugging enabled (your second picture), which also make a difference because the compiler needs to ensure that you can probe these wires, even if they don't lead anywhere useful. Once debugging is disabled, dead code is eliminated significantly more effectively.

 

(Of course debugging also gets typically stripped out when building an executable. Sorry, I don't have anything to contribute to your "classier" problem 😄 )


I was thinking more about runtime environment than development (I do strip debugging when building), but with debugging disabled in development I could see having this same conversation but in development. So if it's saved and not modified and debugging disabled and BD not open, in development environment it will also get ignored? 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 8 of 8
(1,001 Views)