Why does Upload include compile everytime?

I understand that the check sign is for compiling, right arrow for upload and op-amp/bug symbol to start debugging.

I’m wondering why the project does a compilation run once it has already been compiled and there were no changes made anyway?

To make sure that users upload the latest code. One might forget to compile before uploading and next is surprised that the "new" code is not reflected.

You can search this site; if not mistaken you can disable it (so upload does not compile).

@krischu However, if you do that you MUST put that fact in the first line of any forum requests for help.

Thanks. But isn’t it up to the “make” mechanism in the IDE to find out whether compilation has to occur? That’s how “make” has been working for 50 years. Also STM32CubeIDE works this way.

Make works on saved files, the IDE does not necessarily works on saved files.

I think this is too much. What if user forgets to write code? It is really annoying to wait for compile & link the file which was not updated

If it bothers you that much, don't use the Arduino IDE. Or put in a product request.

Click "cancel" button in the command window of the IDE... or...

To "upload without redundant compile" get to know the command line interface (CLI) https://docs.arduino.cc/arduino-cli/getting-started/

make ensures everything is up-to-date, by recursively building while re-using up-to-date assets. The difference might seem subtle, but it's not "check everything, and then if 'nothing changed', don't do anything else".

If you Verify twice in a row, the second time is faster because of cached assets.

But more to the point, there is a setting since IDE 2.3.4

Arduino › Upload: Auto Verify

  • True if the IDE should automatically verify the code before the upload. True by default. When this value is false, IDE does not recompile the code before uploading the binary to the board. It's highly advised to only set this value to false if you know what you are doing.

One good test of "if you know" is whether you can find that setting.

Hi @krischu.

Arduino IDE does make quite some efforts to avoid unnecessary redundant work during the sketch build. When a sketch is compiled, the compiled objects are cached. On subsequent compilations, Arduino IDE will reuse the cache instead of doing a full recompile if appropriate.

However, you will have noticed that the sketch build process still takes some time even in the case where the cache is reused. There are several reasons for this:

It takes some work to determine whether the cache can be reused. Arduino IDE must determine the exact dependencies of the sketch, then check to see if those dependencies have changed since the time they were cached. The need to perform the "library discovery" process on each sketch build is a cost of making Arduino IDE beginner friendly. Traditionally, you would need to manually define the paths of each of a C++ project's dependencies. That requirement would significantly increase the steepness of the learning curve for the average Arduino beginner. The developers have been working to improve the efficiency of the library discovery process, but it is inherently a computing intensive operation since it involves recursively processing all components of the sketch program to determine the list of dependencies.

Another reason is that the .ino files of the sketch are always recompiled (but other source files in the sketch e.g., .cpp, .c are cached). Caching of the compiled objects for the .ino files is more challenging due to fact that what is compiled is the code after Arduino sketch preprocessing. And it didn't seem very worthwhile to undertake that challenge due to the assumption that the user will almost always have made made changes to the sketch code since the last compilation. However, it turns out that this does indeed happen (e.g., user performs a compilation to check for problems with their sketch, finds it is good, then immediately performs an upload to deploy it to their board). For this reason, the developers are working on implementing a caching system for the .ino files as well: Try harder to not recompile sketch without modifications. by cmaglie · Pull Request #2961 · arduino/arduino-cli · GitHub.

Note that there is and has been work to improve the efficiency of the sketch build process. So it is definitely a good idea to keep your Arduino IDE updated in order to reap the benefits of that work.