Lower the number of cc1plus compilation threads

Hi all

I often crash my raspberry pi when compiling esphome sensors and stuff, and noticied that it might be caused by the number of compilation threads which is 4 by default.

Is there any configuration item in the esphome addon to set the number of threads to a lower value ?

Many thanks

Doesn’t help at all, can you point me to the the right change I need to make please?

This is uncalled for. @nickrout has provided you the first step towards a likely answer. The PlatformIO options allow you to control the compilation. Look at the link inside that section.

this is pretty useless, there are no option to decrease concurrency …

Really? Don’t think you are right, but what have you tried?

From memory, I checked and found that the number of threads is forced/equal to number of CPU Cores, that could be improved with some prarameter to specify the number of compliation threads (-j parameter)

I just don’t understand where to adjust it… I cannot find the platformio.ini file.

Looks like the problem was in not enough ram, so I increased my swap file and now it’s fine.
Thanks !

To clarify this:

There appears to be a command-line parameter to pio -j that you can use, however that’s not exposed via the platformio.ini and thus not available through platformio_options.

If you want to reduce the number of CPUs used (ie to do other things) but not reduce the number of jobs you can use taskset -c 0-3 esphome compile your.yaml (for example to only use the first 4 CPUs). HOWEVER this is counter-productive if you are trying to reduce RAM usage - you’ll at best have no impact.

As discussed increasing swap file is a way to not get outright crashes, at the cost of enormous slowdowns, but it doesn’t do what is needed reduce the load to a level that will make efficient use of the hardware in use.

Slightly late to the game (I struggled to find this as well) and for future reference:

  1. Go To: Settings / Add-ons / ESPHome / Configuration
  2. Toggle the " Show unused optional configuration options" button
  3. Look for “Default Compile Process Limit” and set this to 3 or 2 (on my Raspi 4 with 2GB mem, I had to set it to 2 to behave nicely)
  4. After that, Save and restart the add-on.
2 Likes

Yeah it’s been 4 years since, but never too late however as this could help others in the same situation. I have migrated my HA instance to a my NAS, and to a dedicated Intel NUC afterwards

That addon config was probably added in a newer version, but thanks I set this as THE solution for this thread.