Skip to content

perf(fill): shrink fill_n index buffer to 4096 entries - #454

Open
henryiii wants to merge 1 commit into
boostorg:developfrom
henryiii:perf/fill-buffer-size
Open

henryiii wants to merge 1 commit into
boostorg:developfrom
henryiii:perf/fill-buffer-size

Conversation

@henryiii

@henryiii henryiii commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This was found while looking at regressions in #452. The current index buffer overflows the L1 cache. Shrinking it to fit in L1 improves performance.

🤖 AI text below 🤖

The index buffer in fill_n_nd holds 16384 entries (128 kB), which spills out of L1 on recent CPUs. With 4096 entries (32 kB) bulk fills where every value lands in the same bin run about 2x faster. All other cases are unchanged, including 2D, 3D, unlimited_storage and weighted fills. Stack usage drops by 96 kB.

Measured on Apple M5 Pro with Apple clang 21 and gcc 16 at -O3, 262144 values per call, median of three runs, ns per value:

bulk case clang develop clang PR gcc develop gcc PR
default/above 1.54 0.72 1.46 0.82
default/below 1.58 0.69 1.47 0.84
default/edge (all values 1.0) 1.53 0.69 1.52 0.84
default/inside (uniform) 0.71 0.72 0.68 0.67
default/normal 0.72 0.70 0.69 0.68
closed/inside 0.96 0.92 1.05 1.05

This is independent of #452 and #453 and is also included there; those will be rebased once this is in.

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
@henryiii henryiii changed the title perf: shrink fill_n index buffer to 4096 entries perf(fill): shrink fill_n index buffer to 4096 entries Nov 3, 2026

This branch has not been deployed

No deployments
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.

1 participant