-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In ESP32 core version V3.0.5 speed is 30-50% slower than V2.0.17 with Arduino Nano ESP32. #10397
Comments
@lucasssvaz Can we compare the performance with the tests you made? |
Ofcourse? You can also use other ESP32 boards. |
@P-R-O-C-H-Y is talking about including performance test and report in the Arduino Github CI jobs. |
Based on the sketch, it sounds like the difference may be in how FreeRTOS deals with the tasks or there may be more Tasks being executed at the same time in the 3.0.5 version. It is not exactly the HW or System performance. Please add code to list all the RTOS running tasks along the |
We can add a test to check this but as @SuGlider it is probably related to how the FreeRTOS handles the tasks |
@ednieuw - I have tested it. There is a difference as you say. It seems to be the way how the software sets the cores that will run each task. In order to ilustrate it, I have created a sketch that demonstrates how it works within the ESP32-S3 (the same used in ESP32 Nano Board). You may want to change priority, running core, etc // loop() variables
uint32_t Loopcounter = 0;
static uint32_t msTick;
// duplicated to run on separated Task
uint32_t t_Loopcounter = 0;
static uint32_t t_msTick;
#define TASK_PRIO 1 // Lowest = 1 - same as Arduino loop()
void sameLoopTask(void *pvParameters) {
(void) pvParameters;
t_msTick = millis();
while (1) {
t_Loopcounter++;
t_EverySecondCheck();
}
}
void setup()
{
Serial.begin(115200); // Setup the serial port to 115200 baud //
Serial.printf("\r\nArduino is running on Core %d\r\n", ARDUINO_RUNNING_CORE);
Serial.println();
delay(1000);
msTick = millis();
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S3
uint8_t taskCore = ARDUINO_RUNNING_CORE == 0 ? 1 : 0; // runs on the other Core
#else
uint8_t taskCore = 0;
#endif
xTaskCreatePinnedToCore(
sameLoopTask // Task Function
, "Counter Task" // Task Name - text
, 2048 // Stack size
, NULL // When no parameter is used, simply pass NULL
, TASK_PRIO // Priority - Arduino Setup/Loop Task has priority 1 (lowest)
, NULL // With task handle we will be able to manipulate with this task.
, taskCore // Core on which the task will run 0, 1, tskNO_AFFINITY
);
}
void loop()
{
Loopcounter++;
EverySecondCheck();
}
//--------------------------------------------//
// COMMON Update routine done every second
//--------------------------------------------
void EverySecondCheck(void)
{
uint32_t msLeap = millis() - msTick; //
if (msLeap > 999) // Every second enter the loop
{
msTick = millis();
Serial.printf("Loops per second: %ld\n", Loopcounter);
Loopcounter = 0;
}
}
void t_EverySecondCheck(void)
{
uint32_t t_msLeap = millis() - t_msTick; //
if (t_msLeap > 999) // Every second enter the loop
{
delay(1); // feed the dog (WDT)
Serial.printf("TASK:: Loops per second: %ld\n", t_Loopcounter);
t_Loopcounter = 0;
t_msTick = millis();
}
} Output using S3 + ESP32 Arduino Core 3.0.5
|
Doesn't the "Arduino" |
I have investigated the issue and found the root cause: ESP32 Arduino UART Driver. In order to replicate the issue in the Nano ESP32, it is necessary to force the UART0 to start: uint32_t Loopcounter = 0;
static uint32_t msTick;
void setup()
{
Serial.begin(115200); // Setup the serial port to 115200 baud //
msTick = millis();
Serial0.begin(115200); // THIS Line starts UART Arduino Driver and also starts an additional Task that "eats" CPU time...
}
void loop()
{
Loopcounter++;
EverySecondCheck();
}
//--------------------------------------------//
// COMMON Update routine done every second
//--------------------------------------------
void EverySecondCheck(void)
{
uint32_t msLeap = millis() - msTick; //
if (msLeap >999) // Every second enter the loop
{
msTick = millis();
Serial.printf("Loops per second: %u\n",Loopcounter);
Loopcounter = 0;
}
} |
Based on the testing I have done here, this is the root cause. I'll work on a patch. |
After testing the sketch from the issue, it seems clear that IDF 4.x and 5.x UART Driver used by ESP32 Arduino HardwareSerial is not efficient and causes a huge performance issue. The evidence is that whenever Serial0.begin() is executed, there is a significative time slot reduction to the main Arduino Task, affecting the time that loop() has to process data. In Arduino Core 1.0.6, the UART driver was local one, faster and way more efficient. |
The whole issue is, indeed, related to I managed a way to check if the sketch has declared PR #10428 shall solve the issue here reported. |
Results with ESP32 (dual core):
After the PR:
|
I also searched for a delay in hardwareserial but I did not noticed this. It was a lovely bug and in the end an easy solution |
On ESP32 core v2.0.18_rc3 the dual core counter sketch works fine. Loops per second: 689880 When choosing the ESP32 core 3.0.5 I loose my COM11 after upload that changes to COM9 ESP32 family when using IDE2. Uploading the Blink sketch and the Arduino Nano ESP32 is happy again and my own loopcounter sketch also works fine Loops per second: 734550 |
Board
Arduino Nano ESP32
Device Description
Arduino Nano ESP32
Hardware Configuration
Nothing attached
Version
v3.0.4
IDE Name
Arduino IDE 1.0 and 2.0
Operating System
Windows 11
Flash frequency
NA
PSRAM enabled
no
Upload speed
NB Arduino settings in board
Description
I noticed while transferring a large Arduino sketch on an Arduino Nano ESP32 from ESP32 core version 2.0.17 to ESP32 core V3..0.5 the software loop speeds dropped from 220,000 to 169,000 loops per second.
The speed reduction is also with versions 3.0.1 - 3.0.4
With the sketch below the speed reduction is even more and almost 50%.
I did not test the ESP32 Zero and C3-12F board with the ESP32 V2 core but I expect the same results in speed differences
Below the 'Loops per second' when adding one to the loop counter for one second.
No difference noticed using uint64_t or uint32_t
*** Arduino Nano ESP32 board on Arduino ESP32 core V2.0.17
Loops per second: 737744
Loops per second: 734583
Loops per second: 734451
Loops per second: 734451
Loops per second: 734451
Loops per second: 734451
*** Processors on V3.0.5
Arduino Nano ESP32
Loops per second: 380670
Loops per second: 380709
Loops per second: 380726
Loops per second: 380724
Loops per second: 380727
ESP32 S3 Zero
Loops per second: 382485
Loops per second: 382488
Loops per second: 382487
Loops per second: 382487
Loops per second: 382487
ESP32-C3-12F
Loops per second: 125696
Loops per second: 126240
Loops per second: 125695
Loops per second: 126241
Loops per second: 125695
Loops per second: 126240
Loops per second: 125696
Sketch
Debug Message
Other Steps to Reproduce
NA
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: