Skip to content

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Nov 7, 2025

Summary

Adds blog post documenting breaking changes in Event entity class across two PRs in 2025.11.0 release.

Two PRs in same release:

  1. PR #11463 (merged): std::setstd::string → FixedVectorstd::string
  2. PR #11767 (this blog post): FixedVectorstd::string → FixedVector<const char *>

Combined breaking changes (for external components):

  • Event type storage changed from std::set<std::string> to FixedVector<const char *>
  • Eliminates ~80 bytes std::set overhead + per-node overhead + std::string heap allocations
  • Stores event type strings in flash (ESP32) or rodata (ESP8266)
  • Breaking: Loop variables must change from const std::string & to const char *
  • Breaking: Comparisons must use strcmp() instead of == operator
  • Breaking: get_event_types() returns const FixedVector<const char *> & instead of std::set<std::string>
  • Breaking: last_event_type field now private - use get_last_event_type() getter (ensures pointer lifetime safety)
  • Setter accepts initializer_list, FixedVector, or std::vector (same pattern as Select options)
  • Initializer list syntax still works (no core components needed changes except web_server)
  • Lookups changed from O(log n) tree traversal to O(n) linear search with strcmp (faster for typical 1-5 event types due to cache locality)

Blog post includes:

  • Motivation: Event type memory footprint (std::set + std::string overhead for small datasets)
  • Complete change from std::setstd::string to FixedVector<const char *>
  • Platform-specific benefits (ESP32 flash storage, ESP8266 rodata + no std::string overhead)
  • Setter/getter signature changes (accepts initializer_list, FixedVector, or std::vector)
  • Migration guide with strcmp examples
  • FixedVector<const char *> benefits (single allocation, no reallocation overhead)
  • Performance context for small datasets (1-5 items)
  • Pointer lifetime safety with private last_event_type
  • References to both PR #11463 (std::set → FixedVectorstd::string) and PR #11767 (FixedVector<const char *>)

@netlify
Copy link

netlify bot commented Nov 7, 2025

Deploy Preview for esphome-dev-docs ready!

Name Link
🔨 Latest commit d943bfc
🔍 Latest deploy log https://app.netlify.com/projects/esphome-dev-docs/deploys/690e68b3fe8de00008cbd004
😎 Deploy Preview https://deploy-preview-71--esphome-dev-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bdraco
Copy link
Member Author

bdraco commented Nov 7, 2025

We should probably do the const char * change now to avoid two different breaking changes

@bdraco bdraco closed this Nov 7, 2025
@bdraco bdraco reopened this Nov 7, 2025
@bdraco bdraco marked this pull request as ready for review November 7, 2025 21:46
Copilot AI review requested due to automatic review settings November 7, 2025 21:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces comprehensive documentation for memory optimization changes to ESPHome's Event entity class in version 2025.11.0. The changes explain how event type storage has been optimized from std::set<std::string> to FixedVector<const char *> to reduce heap usage and store strings in flash memory.

Key Changes

  • Documents the transition from std::set<std::string> to FixedVector<const char *> for event type storage
  • Provides detailed migration guide for external component developers
  • Explains memory and performance benefits of the optimizations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


## Timeline

- **ESPHome 2025.11.0 (November 2025):**
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The date 'November 2025' appears to be incorrect. The file is named '2025-11-07-event-entity-optimizations.md' which indicates November 7, 2025, but the current date context suggests this may be a future date that hasn't occurred yet. Please verify this is the intended release date.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants