Add sm_pool utility and cache-locality batch benchmarks#3
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new utility sm_pool to the Boost.SML library that enables pooled state machine storage with indexed event dispatch. The main goal is to address cache locality issues when managing many (10k+) state machine instances by allowing a single SML router over contiguous storage with batched dispatch capabilities.
Changes:
- Introduces
boost::sml::utility::sm_poolclass template for managing pooled state machines - Adds comprehensive benchmarks comparing cache locality performance of different dispatch patterns
- Integrates the new benchmark into the build system
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| include/boost/sml/utility/sm_pool.hpp | New utility header providing sm_pool class template with indexed event dispatch and batch processing APIs |
| benchmark/connection/tensor_cache_locality.cpp | Comprehensive benchmark suite comparing per-actor SML, pooled SML, and direct dispatch patterns for cache locality analysis |
| benchmark/connection/Makefile | Adds tensor_cache_locality.cpp to the benchmark build targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } // namespace utility | ||
|
|
||
| BOOST_SML_NAMESPACE_END |
There was a problem hiding this comment.
The namespace closing order is incorrect. The BOOST_SML_NAMESPACE_END macro should come before the utility namespace closing brace, consistent with dispatch_table.hpp. Currently, the utility namespace is inside boost::ext::sml::v1_1_13, but it should be outside. This causes the utility to be placed in boost::ext::sml::v1_1_13::utility instead of boost::ext::sml::utility, breaking namespace consistency.
| } | ||
|
|
||
| struct flat_tensor_pool { | ||
| explicit flat_tensor_pool() : slots(kTensorCount) {} |
There was a problem hiding this comment.
The explicit keyword on a default constructor is unnecessary and unconventional. The explicit keyword is used to prevent implicit conversions for constructors with parameters. For a default constructor with no parameters, it has no practical effect and should be removed for clarity and consistency with other pool constructors in this file.
| explicit flat_tensor_pool() : slots(kTensorCount) {} | |
| flat_tensor_pool() : slots(kTensorCount) {} |
Summary
boost::sml::utility::sm_poolfor indexed event dispatch over pooled storagesm_pool(process_event_batch/process_indexed_batch)benchmark/connection/tensor_cache_locality.cppand wire it intobenchmark/connection/MakefileWhy
This isolates and addresses the 10k actor cache-locality issue by allowing a single SML router over contiguous storage and batched dispatch.
Local benchmark snapshot (median, CPU)
Compared to per-actor SML, pooled batch dispatch cuts random no-data dispatch latency by roughly ~80% in this benchmark.
Validation
benchmark/connection/tensor_cache_locality.cppwithTEST_GBENCH--benchmark_filter='BM_dispatch_(direct_actor_array_random|sml_actor_array_random|sml_pool_random|sml_pool_batch_random)'--benchmark_min_time=0.2s --benchmark_repetitions=5 --benchmark_report_aggregates_only=true