Skip to content

Conversation

@lumia431
Copy link
Owner

Implement configurable Small Buffer Optimization (SBO) for reaction framework resources to eliminate heap allocations for small reactive variables.


Open in Cursor Open in Web

This commit introduces Small Buffer Optimization (SBO) to the Reaction framework. SBO allows small, trivially destructible types to be stored directly within the reactive node, avoiding heap allocations and improving performance.

Key changes include:

- **`OptimizedResource<Type>`**: A new resource implementation that uses SBO for eligible types.
- **`ResourceImpl<Type>`**: A type alias in `resource_selector.h` that conditionally uses `OptimizedResource` or the standard `Resource` based on the `REACTION_ENABLE_SBO` macro.
- **SBO Criteria**: Defined by size (<= 32 bytes), trivial destructibility, and standard alignment.
- **Benchmarks**: Added `bench_sbo.cpp` to compare performance of standard vs. SBO implementations.
- **Unit Tests**: Added `test_sbo_optimization.cpp` to verify SBO functionality.
- **Documentation**: Added `docs/SBO_OPTIMIZATION.md` and `SMALL_MEMORY_OPTIMIZATION_SUMMARY.md` to explain SBO.
- **Example**: Added `example/sbo_example.cpp` to demonstrate SBO usage.

SBO is disabled by default to ensure backward compatibility. It can be enabled by defining `REACTION_ENABLE_SBO` before including Reaction headers.

Co-authored-by: 844727475lmy <[email protected]>
@cursor
Copy link

cursor bot commented Sep 29, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

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.

3 participants