Why does it take so long to compile? Is there any way to make it run faster? I am using Electrosmith Daisy SM STM32 H7 microcontroller with Arduino IDE 2.3.1 latest update. I turned off virus and firewall to see if it was blocking but makes no difference. This makes development so long and frustrating. I'm sure it was faster before this latest update but can't find a previous version like 2.1.0 to compare.
In comparison when I select Arduino Uno it runs fast, as you would expect.
The readout says: Sketch uses 16224 bytes (12%) of program storage space vs Arduino Uno: Sketch uses 444 bytes (1%) of program storage space.
Hi @justinjools. It is inevitable that compilations will be longer when compared to the Uno. The reason is that, even for a minimal sketch, there will still be a lot more code to compile under the hood for a feature rich microcontroller like the H7.
I think that 2 minutes for each compilation is probably in the range we would expect if you have a low spec computer. If you have a higher spec computer then it would be exceptional. When people report exceptionally slow compilations, we often find that it was caused by security/antivirus software on the user's computer. Arduino IDE creates a large number of short duration processes during the compilation. Some antiviruses do "real-time"/"on access" scanning of processes. The process is blocked until the scan is completed. The added time for each scan is quite significant in relation to the duration of the process, so the total impact of the many scans is a great increase in the length of the compilation.
As an experiment, you can try TEMPORARILY disabling the security software/antivirus on your computer for a single compilation to see if the problem goes away:
Disable the security software/antivirus software.
Compile the sketch, just as you did before.
Wait for the compilation to finish.
Immediately enable the security software/antivirus software again.
If the problem doesn't occur when you tried a compilation while the security software was disabled, you will need to adjust the settings of your antivirus to put the appropriate file, folder, or process on the "allowlist" so it doesn't interfere with compilation.
Please be cautious about working with the security software disabled. This is only about temporarily disabling it for a quick test. If you don't feel comfortable doing that, fine. You can try going straight to configuring the security software so that it does not interfere with the Arduino software.
ⓘ Arduino IDE does caching during compilation, so subsequent compilations will be faster than the first one. So take care to avoid that unrelated difference throw off your results when you are comparing compilation times.
I can appreciate it would take longer but waiting 2 minutes every time I need to test code isn't very workable either. I have a Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz 2.11 GHz with 8 GB Windows 11, which runs all other software well.
So there is no way I can optimise the speed? I saw someone mention using a different compiler for C++ but have no idea if this works - The GNU Compiler Collection (GCC).
Arduino IDE actually uses GCC to compile your sketch. However, you might well find that using GCC via an alternative build system would reduce the compilation times.
One factor is the library discovery phase of the Arduino sketch build process. When using an Arduino development tool, we can use a library by simply adding an #include directive to our code. This is possible because the sketch build system searches through all your installed libraries to find the one that provides the header file matching each #include directive. That searching of the file system adds some overhead to the build process (how much depends on the number of libraries used by the sketch, the number of libraries you have installed, and the speed your computer is able to search the file system). With a traditional C++ build system, you would tell the compiler the path of each of the project's library dependencies. Some beginners would have a tremendous amount of difficulty accomplishing such a thing, but an experienced user will have no trouble and might not find it too inconvenient.
Another factor is that the Arduino IDE application uses a significant amount of memory and CPU. On a more capable system, there is plenty enough resources for the IDE and the compilation processes but on a system with less resources the overhead of the IDE application might not leave a lot left for the compilation process to use. You would likely not reduce this much by switching from Arduino IDE to using a different C++ IDE with equivalent feature set. However, you could reduce the overhead by using an IDE with less features. For example, Arduino IDE 1.x is more lightweight (as well as missing some convenient features). If you want to try Arduino IDE 1.x, the download links are listed here:
Alone those same lines, you could eliminate all the GUI overhead entirely if you gave up on using an IDE. This is likely the path you would end up going down if you decided to abandon the Arduino framework entirely, but there is a middle ground. Arduino provides a command line tool named Arduino CLI. This tool allows you to compile, upload, install libraries, install boards platforms, etc. just as you do in Arduino IDE, but from the command line. In fact, Arduino CLI provides most of the non-GUI functionality to Arduino IDE. The compilation process is exactly the same with Arduino CLI (it is the tool that orchestrates the compilation for Arduino IDE), but Arduino CLI uses much less of your system resources so more is available for the compilation processes to use. You can install Arduino CLI by following instructions here:
Interesing, I might try this in future. While I really like Arduino IDE and think it's a great tool for programming Arduino it is too slow for Electrosmith Daisy controllers. I decided to go the C++ route using Visual Studio Code which works without any of the problems I encountered using Arduino.