Skip to content

Add sm_pool utility and cache-locality batch benchmarks#3

Merged
gabewillen merged 1 commit into
mainfrom
sm-pool-batch-benchmark
Feb 23, 2026
Merged

Add sm_pool utility and cache-locality batch benchmarks#3
gabewillen merged 1 commit into
mainfrom
sm-pool-batch-benchmark

Conversation

@gabewillen

Copy link
Copy Markdown

Summary

  • add boost::sml::utility::sm_pool for indexed event dispatch over pooled storage
  • add batch APIs to sm_pool (process_event_batch / process_indexed_batch)
  • add benchmark/connection/tensor_cache_locality.cpp and wire it into benchmark/connection/Makefile
  • include no-data dispatch microbenchmarks for per-actor SML vs pooled SML vs direct baseline

Why

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)

  • direct actor array random: ~14.7us
  • per-actor SML random: ~120.2us
  • pooled SML random: ~40.7us
  • pooled SML batch random: ~24.2us

Compared to per-actor SML, pooled batch dispatch cuts random no-data dispatch latency by roughly ~80% in this benchmark.

Validation

  • built and ran: benchmark/connection/tensor_cache_locality.cpp with TEST_GBENCH
  • command:
    • --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

Copilot AI review requested due to automatic review settings February 23, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown

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 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_pool class 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.

Comment on lines +93 to +95
} // namespace utility

BOOST_SML_NAMESPACE_END

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
}

struct flat_tensor_pool {
explicit flat_tensor_pool() : slots(kTensorCount) {}

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
explicit flat_tensor_pool() : slots(kTensorCount) {}
flat_tensor_pool() : slots(kTensorCount) {}

Copilot uses AI. Check for mistakes.
Comment thread include/boost/sml/utility/sm_pool.hpp
@gabewillen gabewillen merged commit 7c3edee into main Feb 23, 2026
14 checks passed
@gabewillen gabewillen deleted the sm-pool-batch-benchmark branch February 23, 2026 06:53
@gabewillen gabewillen restored the sm-pool-batch-benchmark branch February 23, 2026 07:01
@gabewillen gabewillen deleted the sm-pool-batch-benchmark branch February 23, 2026 07:08
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