Skip to content

Comments

Reuse buffers in ServerMessage<BsatnFormat>#2911

Merged
bfops merged 2 commits intomasterfrom
centril/subs-less-alloc
Dec 18, 2025
Merged

Reuse buffers in ServerMessage<BsatnFormat>#2911
bfops merged 2 commits intomasterfrom
centril/subs-less-alloc

Conversation

@Centril
Copy link
Contributor

@Centril Centril commented Jul 2, 2025

Description of Changes

Fixes #2824.

Defines a global pool BsatnRowListBuilderPool which reclaims the buffers of a ServerMessage<BsatnFormat> and which is then used when building new ServerMessage<BsatnFormat>s.

Notes:

  1. The new pool BsatnRowListBuilderPool reports the same kind of metrics to prometheus as PagePool does.
  2. BsatnRowListBuilder now works in terms of BytesMut.
  3. The trait method fn to_bsatn_extend is redefined to be capable of dealing with BytesMut as well as Vec<u8>.
  4. A trait ConsumeEachBuffer is defined from ServerMessage<BsatnFormat> and down to extract buffers. <ServerMessage<_> as ConsumeEachBuffer>::consume_each_buffer(...) is then called in messages::serialize(...) just after bsatn-encoding the entire message and before any compression is done. This is the place where the pool reclaims buffers.

Benchmarks

Benchmark numbers vs. master using cargo bench --bench subscription -- --baseline subs on i7-7700K, 64GB RAM:

footprint-scan          time:   [21.607 ms 21.873 ms 22.187 ms]
                        change: [-62.090% -61.438% -60.787%] (p = 0.00 < 0.05)
                        Performance has improved.

full-scan               time:   [22.185 ms 22.245 ms 22.324 ms]
                        change: [-36.884% -36.497% -36.166%] (p = 0.00 < 0.05)
                        Performance has improved.

The improvements in footprint-scan are mostly thanks to #2918, but 7 ms of the improvements here are thanks to the pool. The improvements to full-scan should be only thanks to the pool.

API and ABI breaking changes

None

Expected complexity level and risk

2?

Testing

  • Tests for Pool<T> also apply to BsatnRowListBuilderPool.

@Centril Centril force-pushed the centril/subs-less-alloc branch 4 times, most recently from f4b0fb9 to ed80830 Compare July 2, 2025 14:40
@Centril Centril marked this pull request as ready for review July 3, 2025 09:53
@Centril Centril requested a review from gefjon as a code owner July 3, 2025 09:53
@joshua-spacetime
Copy link
Collaborator

Can you make the first commit its own independent PR?

@Centril
Copy link
Contributor Author

Centril commented Jul 3, 2025

Can you make the first commit its own independent PR?

Will do 👍

@Centril Centril force-pushed the centril/subs-less-alloc branch 3 times, most recently from 0e9622d to 6b90886 Compare July 4, 2025 09:04
@Centril Centril changed the base branch from master to centril/execute-plan-no-temp-vecs July 4, 2025 09:04
@Centril Centril force-pushed the centril/subs-less-alloc branch 3 times, most recently from 5f2394e to b961e78 Compare July 4, 2025 09:48
@Centril Centril force-pushed the centril/subs-less-alloc branch from b961e78 to bbeec32 Compare July 4, 2025 10:06
@Centril Centril changed the base branch from centril/execute-plan-no-temp-vecs to centril/object-pool July 4, 2025 10:06
@Centril Centril force-pushed the centril/subs-less-alloc branch 3 times, most recently from a7aa61a to b0cc2d4 Compare July 4, 2025 11:47
@Centril Centril force-pushed the centril/object-pool branch 2 times, most recently from fa008fb to 9411e5e Compare July 4, 2025 13:27
Base automatically changed from centril/object-pool to master July 4, 2025 14:14
@Centril Centril force-pushed the centril/subs-less-alloc branch 2 times, most recently from f3be26f to f112436 Compare July 4, 2025 14:21
@Centril Centril changed the base branch from master to centril/execute-plan-no-temp-vecs July 4, 2025 14:21
@Centril Centril force-pushed the centril/subs-less-alloc branch from d23f3ff to 72a3dab Compare December 18, 2025 08:36
@Centril Centril changed the base branch from centril/durability-worker to master December 18, 2025 08:36
@Centril Centril enabled auto-merge December 18, 2025 09:54
@Centril Centril added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@Centril Centril added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@Centril Centril added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 18, 2025
@bfops bfops added this pull request to the merge queue Dec 18, 2025
Merged via the queue into master with commit 8e3af49 Dec 18, 2025
27 checks passed
@Centril Centril deleted the centril/subs-less-alloc branch December 19, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance A PR/Issue related to improving performance of stdb release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add buffer pool for serializing subscription results

5 participants