⚡ Optimize the context layout and allocation strategy#95
Merged
Conversation
\## Summary Replace `std::span<stack_word> m_stack` with two raw pointers (`m_stack_pointer`, `m_stack_end`), saving one word in the context object and bringing hot fields into the first cache line. Capacity is stored in the sentinel slot at `m_stack_end` rather than in span metadata. \## Changes - Replace `m_stack` span with `m_stack_pointer` + `m_stack_end` pointers - Store capacity in `m_stack.back()` and read it back via `*m_stack_end` - Reorder members to pack `m_state` and `m_sleep_time` before the pointers, fitting more into the first cache line - Fix `inplace_context` constructor to call `initialize_stack_memory()` in the body rather than the initializer list — member zero-init runs after the base constructor and would otherwise clobber the capacity sentinel written into `m_stack.back()` - Update `sync_wait` tests to capture `ctx.capacity()` at construction instead of comparing against the raw template argument (capacity is now `N - 1` due to the reserved sentinel slot) \## Test Plan - [x] Pre-commit checks pass - [x] New/updated tests cover the changes - [x] Tested locally with `conan create .`
5f7a19c to
9d0113b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
std::span<stack_word> m_stackwith two raw pointers (m_stack_pointer,m_stack_end), saving one word in the context object and bringing hot fields into the first cache line. Capacity is stored in the sentinel slot atm_stack_endrather than in span metadata.Changes
m_stackspan withm_stack_pointer+m_stack_endpointersm_stack.back()and read it back via*m_stack_endm_stateandm_sleep_timebefore the pointers, fitting more into the first cache lineinplace_contextconstructor to callinitialize_stack_memory()in the body rather than the initializer list — member zero-init runs after the base constructor and would otherwise clobber the capacity sentinel written intom_stack.back()sync_waittests to capturectx.capacity()at construction instead of comparing against the raw template argument (capacity is nowN - 1due to the reserved sentinel slot)Test Plan
conan create .