Skip to content

Reduce capacity to stay within multi-pool allocator ceiling - #415

Open
cameron314 wants to merge 1 commit into
bloomberg:mainfrom
cameron314:reduce-execute-alloc
Open

Reduce capacity to stay within multi-pool allocator ceiling#415
cameron314 wants to merge 1 commit into
bloomberg:mainfrom
cameron314:reduce-execute-alloc

Conversation

@cameron314

Copy link
Copy Markdown
Contributor

The deferred functor queue maintained by Chronology is swapped out with an empty container when it is drained by announce(). The next call to execute() re-reserves capacity for many functors. The intention was for the backing memory to come from the multi-pool allocator (making the pattern of reserve-swap-reserve-swap-... much cheaper). However, the chosen capacity was larger than the maximum size of the multi-pool, causing it to perform a true heap allocation/deallocation on each cycle, which was significantly more expensive.

I've changed the constant and added an assertion to insure against future regressions. I've verified the assertion fails while running the unit tests with the original constant.

Note that on a 64-bit test machine, sizeof(bsl::function<void()>) is currently 80 bytes.


Empirical testing shows the following reduction in overhead:

Before: 118 samples, heap allocations
image

After: 108 samples, pool allocations

image

…ue heap allocations on interleaved calls to execute()/announce())
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