Hello.
In this lecture, we're going to talk about Topic 48.
What is the difference between debug and release builds when using Visual Studio?
It's hard not to notice this little option in the top menu.
When developing the code, we most likely use Ladybug mode, and we don't really think much about the
other option.
The release mode as their name suggests, the debug mode is most appropriate when debugging the application,
so mostly during the development and the release mode can be used when we intend to release the application
so it can be used by users or other programs.
But what is the difference between them exactly?
The main difference is that in the released build, the compiler introduces some optimizations it finds
appropriate.
They can be things like removing unused variables or simplifying method calls.
It helps to make the final common intermediate language code smaller, simpler and often faster.
Remember that the common intermediate language is the language to which the compiler compiles this code.
Those optimizations shouldn't be done in the debugging mode because they can make debugging harder as
the compound result doesn't match exactly the source code.
Let's see the simple compiler optimizations in practice.
First, let's see some code that is not optimal.
This variable is not used.
First, I will build this project in the debug mode.
The result of compilation should end up in the Dimmock folder.
The fastest way to go down is by right clicking on the product and selecting Open Folder in File Explorer.
Let's find the compound Diallo.
It is in the Dybbuk folder, a six pack that would I'm going to do now is to first use IL dozen to see
the common intermediate language code.
Then we will translate this code back to C-sharp to see how the compilation affected the structure of
the code.
You can find it does an application under such path.
Let's run it.
Now we can simply drag that yellow and drop it to your Dawson.
To save the common intermediate language called in the file, we must select, file and dump.
And here it is.
Let's open it with Notepad.
Here is the common intermediate language code that's now copied and pasted on this web page.
Chopped up allows us to compile the common intermediate language code to see towards C-sharp code,
it translates to.
And here it is.
Let's fund the program class.
And this is how it looked like originally.
Well, the changes done by the compiler are not very exciting.
We can see that the unused variable has been renamed to something shorter and that the strings have
been learned.
Now let's do the same thing.
But in the release build.
First of all, the result of compensation should end up in the release folder.
Here it is.
I will again drop the deal to elders and save the common intermediate language code and then paste it
to our club.
This time, the Houston variable has been removed completely.
This is just an extremely simple example of what the compiler can optimize in the release mode.
But be aware that those optimizations can be much more serious.
The compiler can simplify or in-line.
The method calls remove whole pieces of code that it doesn't find useful, etc. the algorithm behind
it that is quite sophisticated and it depends on the compiler version as well.
As such, low level details like how big the methods are, we can configure some of the optimization
settings.
For example, if we don't want some method to be in line, we can add the no inclining attribute to
it.
In the article attached to this lecture, I left a link to an article in which you can read more about
that.
The code optimization done by the compiler is the main difference between the debug and release modes.
Please note that if we want some code to be executed only in one of those modes, we can put it in if
debug or if release conditions are pre-processed or directives.
Now this line will be executed if you run the application built in the realist mode.
If you are in the debug mode.
This line will be run.
And here it is, makes sense because the realist mold was selected here.
Let's summarize during the release build, the compiler applies optimizations it finds appropriate.
Because of that, the result of the build is often smaller and it works faster.
On the other hand, it's harder to debug because the compiled result doesn't match the source code exactly.
During the interview.
You can be asked How can we execute some piece of code only in the debug or only in the release mode
by simply placing this code inside?
If the bug or if this conditional preprocessor directives will actually talk more about them in the
next lecture.
Thanks for watching this one, and I'll see you there.