Skip to content

Conversation

@mathieucarbou
Copy link
Contributor

@mathieucarbou mathieucarbou commented Nov 10, 2025

Example: -D CONFIG_ARDUINO_UDP_TASK_STACK_SIZE=2048

The default is to much conservative since a correctly developed app probably won't allocate too much on stack on the callbacks. I currently see a waste of memory:
I (1222501) MONITOR: async_udp (p=3) 3416 bytes

@mathieucarbou mathieucarbou marked this pull request as ready for review November 10, 2025 08:23
@mathieucarbou mathieucarbou requested review from a team and me-no-dev as code owners November 10, 2025 08:23
@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "feat(udp): Allow to change the async_udp task stack size":
    • body's lines must not be longer than 100 characters
    • body must have leading blank line

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 10 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello mathieucarbou, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 6ea62d4

@mathieucarbou mathieucarbou changed the title Udp feat(udp): Allow to change the async_udp task stack size Nov 10, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32C5000.000.00000.000.00
ESP32P4000.000.00000.000.00
ESP32S3💚 -1600.000.00000.000.00
ESP32S2000.000.00000.000.00
ESP32C3000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32000.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/AsyncUDP/examples/AsyncUDPClient00000000000000
libraries/AsyncUDP/examples/AsyncUDPMulticastServer00000000000000
libraries/AsyncUDP/examples/AsyncUDPServer00000000000000
libraries/DNSServer/examples/CaptivePortal0000💚 -16000000000
libraries/NetBIOS/examples/ESP_NBNST00000000000000
libraries/Update/examples/HTTP_Server_AES_OTA_Update00000000000000

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test Results

 76 files   76 suites   16m 41s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commit 6ea62d4.

♻️ This comment has been updated with latest results.

@me-no-dev
Copy link
Member

@mathieucarbou CONFIG_ARDUINO_UDP_TASK_STACK_SIZE might not be normally present when compiling in Arduino IDE. I suggest to check if it's not defined and define it to default value on the top of the file (or header)

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Nov 10, 2025

@mathieucarbou CONFIG_ARDUINO_UDP_TASK_STACK_SIZE might not be normally present when compiling in Arduino IDE. I suggest to check if it's not defined and define it to default value on the top of the file (or header)

Hello,

That's what I did first if you look here: https://github.com/espressif/arduino-esp32/compare/61aaa44254c1ccc4e45eaecbee1cd268e7324795..b3c3a31df445ce1e6990b412e0b1740a50187930

But then I saw that all the macros are only defined in Kconfig.projbuild...

So for this one exceptionally, I should do both ? Is it what you mean ?

Thanks :-)

@me-no-dev
Copy link
Member

Since this has not been merged and the lib-builder did not get a chance to run Kconfig and generate the defines, they do not currently exists in Arduino at all. That is the reason why CI is failing and anyone that would normally try that code now will also get a compile error. Adding check on top will ensure that the code will compile in all cases. The other values are missing because before the libs used to be built in a different way and included in the core. Later the define check could be removed if need be.

There are also better ways to handle this and allow overwrite in Arduino or pioarduino

#ifndef CONFIG_ARDUINO_UDP_TASK_STACK_SIZE
#define CONFIG_ARDUINO_UDP_TASK_STACK_SIZE 4096
#endif
#ifndef ARDUINO_UDP_TASK_STACK_SIZE
#define ARDUINO_UDP_TASK_STACK_SIZE CONFIG_ARDUINO_UDP_TASK_STACK_SIZE
#endif

xTaskCreateUniversal(
      _udp_task, "async_udp", ARDUINO_UDP_TASK_STACK_SIZE, NULL, CONFIG_ARDUINO_UDP_TASK_PRIORITY, (TaskHandle_t *)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE
    );

This way you can -D ARDUINO_UDP_TASK_STACK_SIZE=8192 either in build_opt.h in the sketch folder or in platformio config to change the value and not cause redefine warning

@mathieucarbou
Copy link
Contributor Author

This way you can -D ARDUINO_UDP_TASK_STACK_SIZE=8192 either in build_opt.h in the sketch folder or in platformio config to change the value and not cause redefine warning

Thanks for your help!

Should I do the same for CONFIG_ARDUINO_UDP_RUNNING_CORE and CONFIG_ARDUINO_UDP_TASK_PRIORITY then ?

In my app I set CONFIG_ARDUINO_UDP_RUNNING_CORE to core 0 for example and on purpose since it is running critical in the callback and code I do not want to be impacted by the loop.

@me-no-dev
Copy link
Member

Should I do the same for CONFIG_ARDUINO_UDP_RUNNING_CORE and CONFIG_ARDUINO_UDP_TASK_PRIORITY then ?

Please do. We have overlooked this and since nobody asked for it, we did not catch it

Example:  `-D CONFIG_ARDUINO_UDP_TASK_STACK_SIZE=2048`
The default is to much conservative since a correctly developed app probably won't allocate too much on stack on the callbacks. I currently see a wast of memory:
`I (1222501) MONITOR: async_udp  (p=3) 3416 bytes`
@mathieucarbou
Copy link
Contributor Author

Should I do the same for CONFIG_ARDUINO_UDP_RUNNING_CORE and CONFIG_ARDUINO_UDP_TASK_PRIORITY then ?

Please do. We have overlooked this and since nobody asked for it, we did not catch it

done!

#ifndef CONFIG_ARDUINO_UDP_TASK_STACK_SIZE
#define CONFIG_ARDUINO_UDP_TASK_STACK_SIZE 4096
#endif
#ifndef ARDUINO_UDP_TASK_STACK_SIZE
#define ARDUINO_UDP_TASK_STACK_SIZE CONFIG_ARDUINO_UDP_TASK_STACK_SIZE
#endif

#ifndef CONFIG_ARDUINO_UDP_TASK_PRIORITY
#define CONFIG_ARDUINO_UDP_TASK_PRIORITY 3
#endif
#ifndef ARDUINO_UDP_TASK_PRIORITY
#define ARDUINO_UDP_TASK_PRIORITY CONFIG_ARDUINO_UDP_TASK_PRIORITY
#endif

#ifndef CONFIG_ARDUINO_UDP_RUNNING_CORE
#define CONFIG_ARDUINO_UDP_RUNNING_CORE -1
#endif
#ifndef ARDUINO_UDP_RUNNING_CORE
#define ARDUINO_UDP_RUNNING_CORE CONFIG_ARDUINO_UDP_RUNNING_CORE
#endif

I set -1 like it is done at other places, hopping this is ok for async udp too.

@me-no-dev
Copy link
Member

I set -1 like it is done at other places, hopping this is ok for async udp too.

It is. xTaskCreateUniversal will turn it to 0 if chip is single core

@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Nov 10, 2025
Copy link
Collaborator

@SuGlider SuGlider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@me-no-dev me-no-dev merged commit 2bb78a9 into espressif:master Nov 10, 2025
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Pending Merge Pull Request is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants