Skip to content

Conversation

@jimmyw
Copy link
Contributor

@jimmyw jimmyw commented Oct 30, 2025

Description

In my quest to improve heap fragmentation, i noticed that the webserver was a big issue, but not for the reasons you think. A single web page read/write causes several esp_events to be sent, each one causing a malloc on its own and a contex switch to handle tasks. And the worst part of it, is that we never listened on any of these events.

This PR adds a KConfig option to disable events on the webserver, this was a hug improvement for us in 5.4.1


Note

Adds Kconfig switches to enable/disable HTTP(S) server events and gates event declarations/dispatches, with no-ops when disabled; examples updated accordingly.

  • Config:
    • Add CONFIG_HTTPD_ENABLE_EVENTS and CONFIG_ESP_HTTPS_SERVER_EVENTS to toggle ESP_HTTP_SERVER_EVENT/ESP_HTTPS_SERVER_EVENT.
    • Event post timeouts now depend on these flags.
  • esp_http_server:
    • Wrap ESP_EVENT_DECLARE_BASE, esp_http_server_event_data, and ESP_EVENT_DEFINE_BASE with CONFIG_HTTPD_ENABLE_EVENTS.
    • Provide esp_http_server_dispatch_event() only when enabled; define as no-op otherwise.
    • Guard event postings in httpd_main.c/httpd_txrx.c and maintain http_server_state updates.
  • esp_https_server:
    • Wrap event base/dispatch and postings with CONFIG_ESP_HTTPS_SERVER_EVENTS; define no-op dispatcher when disabled.
    • Update SPDX year.
  • Examples:
    • Conditionally register HTTPS server event handlers only when events are enabled.

Written by Cursor Bugbot for commit bd85dad. This will update automatically on new commits. Configure here.

@cursor
Copy link

cursor bot commented Oct 30, 2025

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on November 20.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions
Copy link

github-actions bot commented Oct 30, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello jimmyw, 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.
- 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 via this public GitHub repository.

This GitHub project is public mirror of our internal git repository

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 synchronize it into our internal git repository.
4. In the internal git repository 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.
5. If the change is approved and passes the tests it is merged into the default branch.
5. On next sync from the internal git repository merged change will appear in this public GitHub repository.

Generated by 🚫 dangerJS against bd85dad

@github-actions github-actions bot changed the title feat(esp_http_server): Make HTTP(S)_SERVER_EVENT events optional feat(esp_http_server): Make HTTP(S)_SERVER_EVENT events optional (IDFGH-16707) Oct 30, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 30, 2025

#define ESP_HTTPD_DEF_CTRL_PORT (32768) /*!< HTTP Server control socket port*/

#ifdef CONFIG_HTTPD_ENABLE_EVENTS
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ifdef CONFIG_HTTPD_ENABLE_EVENTS
#if CONFIG_HTTPD_ENABLE_EVENTS || __DOXYGEN__

int fd; /*!< Session socket file descriptor */
int data_len; /*!< Data length */
} esp_http_server_event_data;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif
#endif // CONFIG_HTTPD_ENABLE_EVENTS

extern "C" {
#endif

#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
#if CONFIG_ESP_HTTPS_SERVER_EVENTS || __DOXYGEN__

HTTPS_SERVER_EVENT_DISCONNECTED, /*!< The connection has been disconnected */
HTTPS_SERVER_EVENT_STOP, /*!< This event occurs when HTTPS Server is stopped */
} esp_https_server_event_id_t;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS

}
}
#else
#define http_dispatch_event_to_event_loop(event_id, event_data, event_data_size) do {} while (0)
Copy link
Member

Choose a reason for hiding this comment

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

Could we use similar approach (stub out the implementation) in HTTP server component as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, i had to put the stub in the internal header, but i dont see any issue with that.

@jimmyw jimmyw force-pushed the jimmyw/http_server_event_optional branch 2 times, most recently from fe2dccf to c4ae00e Compare November 21, 2025 10:36
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Make it possible to disable http(s) server events. This improves
performance of the server, as http server creates events on every signle
read or write to the socket.
@jimmyw jimmyw force-pushed the jimmyw/http_server_event_optional branch from c4ae00e to bd85dad Compare November 22, 2025 20:31
@mahavirj
Copy link
Member

sha=bd85dad2cf2e7436eca2d096b85bd5dcecc50875

@mahavirj mahavirj added the PR-Sync-Merge Pull request sync as merge commit label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Sync-Merge Pull request sync as merge commit Status: Opened Issue is new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants