How to make builds faster?

I am playing with the very simple “espidf-hello-world” example.

  • Why does it have to compile hundreds of files that are not used in this project? After all, isn’t that what the libdependency is for?

  • Ok, so let’s just say it has to just to create a symbol table in case it is needed. But why is the same set of files compiled every single time that I make a small change to the hello_wold_main.c? This is such a waste of time!

I’m assuming this is something I’ve misconfigured, so please please tell me how to save myself some 45 seconds per build.

I dont have experience with espidf or other frameworks. But from my experience

  1. LDF works to discover used libraries
  2. chain+ and deep+ modes can skip libraries guarded by conditions that don’t evaluate to true
  3. libraries are compiled in their entirety, i.e. all c files in the library. I was quite taken aback by that at first. As for some libraries you don’t want that and have to use library.json + src_filter options to filter some of the files out. But then it helps with the following:
  4. libraries are archived by default and only recompiled if build flags are changed. So if you use same library with the same build flags, it should reuse the compiled result. Changing your own source could should not require recompiling the dependent libraries. And because libraries are compiled wholesale, including a new file into your library will still re-used pre-compiled library.
  5. size of a binary can be optimized further by -flto build flag which admittedly can add even more delay to build times.

ESP-IDF framework doesn’t use PlatformIO’s library concept to detect only needed code. PlatformIO builds all ESP-IDF source code (or rather, it does so through CMake). ESP-IDF is notorous for having the largest number of source files and the highest compilation times. There isn’t any intelligent logic here to only compile the ESP-IDF components which are needed – the native ESP-IDF build system also doesn’t do that. And since PlatformIO just calls via CMake into ESP-IDF’s build logic, it would need to be fixed there, which it hasn’t for as long as I can remember this framework exists.

That should not happen. Did you change the platformio.ini or a CMake file?

1 Like

I’m not finding this to be consistent across all my projects. I have the sample one above that takes a while to build, every time it builds, but on another real project that I’m working on, the build is only 10s of seconds.