Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

MartyMacGyver
Posts: 56
Joined: Sun Dec 18, 2016 9:17 pm

Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby MartyMacGyver » Wed Sep 20, 2017 6:41 am

I am working on a feature for a library I maintain, to use multiple RMT channels to control multiple digital RGB LED strands. The current feature work is here:
https://github.com/MartyMacGyver/ESP32- ... ultistrand
Note: Eventually that work will be merged and the branch removed - at that point, see the main driver at:
https://github.com/MartyMacGyver/ESP32- ... ED-Drivers

My Arduino-ESP32 and ESP-IDF versions are both recent and both from their respective master branches. Build tools are up-to-date for both.

There's an Arduino-ESP32 version of my library and demo as well as an ESP-IDF version - except for some glue and init code switched via #defines they are virtually identical. The odd thing is, even when empty delays are used (which just return in the ESP-IDF stub I use on that side), the Arduino-ESP32 demo always runs noticeably faster than the ESP-IDF one. This is very odd to me... it's as if the MCU clock speed of the ESP-IDF version was quite a bit faster than the Arduino version.

What might lead to this peculiar difference?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby ESP_Sprite » Wed Sep 20, 2017 7:52 am

Could it perhaps be because the clock frequency actually is different? Not sure how you set it in the arduino environment, but in esp-idf, you can set it using 'make menuconfig' and by default it is set to 160MHz.

MartyMacGyver
Posts: 56
Joined: Sun Dec 18, 2016 9:17 pm

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby MartyMacGyver » Fri Sep 22, 2017 12:28 am

ESP_Sprite wrote:Could it perhaps be because the clock frequency actually is different? Not sure how you set it in the arduino environment, but in esp-idf, you can set it using 'make menuconfig' and by default it is set to 160MHz.
Doubly odd: I never got a notification for this subscribed thread, and the reply I posted a few minutes ago disappeared.

I didn't know the default is 160MHz now (was it always?) I've changed that to 240MHz, re-built and re-flashed. It's a little faster not, but still not nearly as fast as the Arduino build.

I'll dig into the actual options being used during `make` to see if there's anything obvious there.

Edit: nothing obvious so far. The compiler options are pretty much the same.

Edit2: Ah, but the `sdkconfig` in `hardware\espressif\esp32\tools\sdk\sdkconfig` is rather different!

`CONFIG_FREERTOS_HZ=1000 # IDF = 100`

Changing that (and ensuring `CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y` is selected) make it work the same as the Arduino version.

Guess I'll need to start checking in the sdkconfig again... or being very specific about the configuration parameters. Too bad there's no way to add a default config with just the specific switches overriding whatever the defaults are (currently you have to manually answer every new option that appeared since the last SDK config... unless there's a shortcut I'm missing).

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby loboris » Fri Sep 22, 2017 6:53 am

MartyMacGyver wrote: Too bad there's no way to add a default config with just the specific switches overriding whatever the defaults are ...
You can add the default settings to sdkconfig.defaults file in your project directory.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby permal » Fri Sep 22, 2017 7:14 am

Also enable release build in menuconfig, otherwise you'll flash code made for debugging and it is sometimes considerably slower than the optimized version.

MartyMacGyver
Posts: 56
Joined: Sun Dec 18, 2016 9:17 pm

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby MartyMacGyver » Fri Sep 22, 2017 7:32 am

loboris wrote:You can add the default settings to sdkconfig.defaults file in your project directory.
Perfect! Thanks for the tip!

MartyMacGyver
Posts: 56
Joined: Sun Dec 18, 2016 9:17 pm

Re: Program compiled with Arduino-ESP32 runs noticeably faster than the same thing on ESP-IDF - why?

Postby MartyMacGyver » Fri Sep 22, 2017 7:34 am

permal wrote:Also enable release build in menuconfig, otherwise you'll flash code made for debugging and it is sometimes considerably slower than the optimized version.
In this case it was all about the settings I noted, but yes, this was something I tried changing previously (to no noticeable effect).

Who is online

Users browsing this forum: Bing [Bot] and 231 guests