From ed959a8c2c1bb0703b40872b067c270acd11c615 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 3 Nov 2026 11:07:01 -0500 Subject: [PATCH] perf: shrink fill_n index buffer to 4096 entries The 128 kB buffer spills out of L1 on recent CPUs. With 32 kB, bulk fills where every value lands in the same bin run 2x faster on Apple M5 with clang and gcc; other cases are unchanged. Stack usage drops as well. Assisted-by: ClaudeCode:claude-fable-5-1 --- include/boost/histogram/detail/fill_n.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/histogram/detail/fill_n.hpp b/include/boost/histogram/detail/fill_n.hpp index a282a403..0d849ab2 100644 --- a/include/boost/histogram/detail/fill_n.hpp +++ b/include/boost/histogram/detail/fill_n.hpp @@ -219,7 +219,8 @@ void fill_n_storage(S& s, const Index idx, weight_type&& w, Ts&&... ps) noexc template void fill_n_nd(const std::size_t offset, S& storage, A& axes, const std::size_t vsize, const T* values, Ts&&... ts) { - constexpr std::size_t buffer_size = 1ul << 14; + // 32 kB of indices; a larger buffer spills out of L1 and slows the passes below + constexpr std::size_t buffer_size = 1ul << 12; Index indices[buffer_size]; /*