Repository navigation
Write down the allocation model - #237
Merged
Merged
Conversation
The rule the allocation series enforced was stated only in the allocation test's header and PR bodies. ESPHome's operator new draws only on internal RAM and aborts on failure, so after start() connection setup and message handling allocate through the fallible platform_malloc family, and bounded values are held inline. - conventions.md "Embedded resource discipline" states the rule; its Documentation bullet lists the allocation model among internals.md's contents. - internals.md gains a "Memory" section: the allocators and how each fails, what is held inline, a table of the operator new allocations that remain after start(), and the one-pointer capture the std::functions built after start() depend on. - CLAUDE.md names the inline types and what sendspin_alloc_tests counts. - The embedded-review skill checks a new operator new after start().
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The allocation documentation omits post-start allocation sites and an aborting failure path, overstates callback allocation guarantees, and misidentifies noise-c state ownership.
5 open issues
Scope allocator inventory or include host frame allocations · New Include aborting noise-c hash-state allocations in failure description · New Attribute noise-c state ownership to NoiseSession · New Document all post-start allocation sites and their threads · New Limit callback guarantee and account for SBO requirements · New
What changed in this PR
Documents the allocation model established by the allocation-reduction series, giving contributors a shared reference for ESPHome’s internal-RAM and allocation-failure constraints. This PR changes documentation only.
Changes:
- Define post-
start()allocation rules, inline storage expectations, and public-value conversions. - Inventory remaining heap allocations, their timing and threads, and callback storage assumptions.
- Align contributor guidance and the embedded-review checklist with the allocation model.
| File | Description |
|---|---|
docs/internals.md |
Add the memory model and remaining-allocation inventory. |
docs/conventions.md |
Establish allocator and bounded-storage rules. |
CLAUDE.md |
Update memory guidance, documentation references, and allocation-test notes. |
.claude/skills/embedded-review/SKILL.md |
Require new post-start operator new sites to be documented or flagged. |
Review effort: Max
- Scope: the host transport, which copies each frame into a std::string, and the host-only message trace sit outside the model. - Failures: noise-c's hash states are allocated like its others, and platform_random_bytes() and psk_id_for() on a std::array abort when noise-c cannot allocate their state. - NoiseSession alone owns the noise-c handshake and cipher states. - Every table row names its thread; the record store's changed-slot list and group/update's later copies are added. - A std::function capture change is checked against the small buffer rather than assumed to allocate.
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The allocation series (#225-#236) enforced a rule that was written down only in
tests/test_allocations.cpp's header and in PR bodies. ESPHome'soperator newdraws only on internal RAM and aborts on failure, so afterstart()connection setup and message handling allocate through the fallibleplatform_mallocfamily, and bounded values are held inline. This PR states that rule and records where the code still allocates withoperator new. Docs only.Change
docs/conventions.md: "Embedded resource discipline" gains the rule:operator newat construction,add_*()andstart()only; afterwardsplatform_malloc, whose failure refuses or closes the connection or drops the message; bounded values inline (InlineText,InlineVector,EnumSet,std::array); peer text bounded where it is parsed; publicstd::string/std::vectortypes built on the thread that hands them to the consumer. The Documentation bullet lists the allocation model amonginternals.md's contents.docs/internals.md: a new "Memory" section: the three allocators (operator new,platform_malloc, noise-c'scalloc) and how each fails, what is held inline, a table of theoperator newallocations that remain afterstart()with when and on which thread each runs, and the one-pointer capture thestd::functions built afterstart()rely on.CLAUDE.md: the Memory convention names the inline types and points at the new section; the test build note says whatsendspin_alloc_testscounts; both descriptions ofinternals.mdmention memory..claude/skills/embedded-review/SKILL.md: a newoperator newafterstart()is listed in "Memory" or reported as a finding.Tests
Docs only. Each claim in the Memory section was checked against the code; the table is the checklist the remaining allocation groups (tracked in Sendspin/backlog#92) remove rows from.