Skip to content

Add an ArduinoJSON arena defaulting to internal memory#52

Merged
kahrendt merged 2 commits into
mainfrom
json-ram-arena
May 11, 2026
Merged

Add an ArduinoJSON arena defaulting to internal memory#52
kahrendt merged 2 commits into
mainfrom
json-ram-arena

Conversation

@kahrendt
Copy link
Copy Markdown
Contributor

@kahrendt kahrendt commented May 11, 2026

This avoids heap allocation churn while also saving a few CPU cycles by avoiding PSRAM/reducing cache pressure for these routine messages.

Defaults to a 2048 byte arena in internal memory. ArduinoJSON uses 1024 of those bytes for small messages, and the rest is a copy of the original message.

…s heap allocation churn while also saving a few CPU cycles by avoiding PSRAM for these routine messages.
Copy link
Copy Markdown

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 a reusable ArduinoJson allocator backed by a fixed internal-RAM bump arena (with PSRAM/heap fallback) and wires it into SendspinClient::process_json_message() to reduce allocation churn and PSRAM traffic on the network thread.

Changes:

  • Added SendspinArenaAllocator (bounded bump allocator with fallback) and make_json_document(arena) helper.
  • Added SendspinClientConfig::json_arena_size (default 2048 bytes) and a SendspinClient-owned arena reused across incoming JSON messages.
  • Documented the new arena behavior in internal and integration docs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/platform/json_arena.h New internal-RAM bump arena ArduinoJson allocator with PSRAM-preferring fallback.
src/client.cpp Creates optional arena from config and reuses it for parsing incoming JSON messages.
include/sendspin/config.h Adds json_arena_size config knob with default and documentation.
include/sendspin/client.h Adds forward declaration and member for the arena allocator.
docs/internals.md Documents incoming JSON parse arena and updates references to client.cpp.
docs/integration-guide.md Adds json_arena_size to the configuration table.

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

Comment thread src/platform/json_arena.h Outdated
Comment thread docs/internals.md Outdated
Comment thread include/sendspin/config.h Outdated
Comment thread docs/integration-guide.md Outdated
Comment thread include/sendspin/config.h
@kahrendt kahrendt enabled auto-merge (squash) May 11, 2026 19:32
@kahrendt kahrendt merged commit ee1063c into main May 11, 2026
4 checks passed
@kahrendt kahrendt deleted the json-ram-arena branch May 11, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants