Skip to content

reuse existing capacity in sbo_buffer::grow - #1178

Closed
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:sbo-buffer-grow-capacity
Closed

reuse existing capacity in sbo_buffer::grow#1178
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:sbo-buffer-grow-capacity

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: a 200-element [1.25,...] array (1001 bytes) fed to stream_parser a byte at a time with number_precision::precise, so every number straddles a write_some boundary, makes 813 global operator new calls totalling 56.1 GB with a largest single block of 1.14 GB; a 32 KB body in 4 KiB chunks peaks at a 2.2 MB block, and that peak keeps doubling as the body grows.
Cause: grow never checks whether the buffer already has room, so every append reallocates and each one floors the new capacity at old_capacity * 2, while clear keeps the block, so the doubling carries across numbers and across reset, and the inline buffer goes unused past the first append.
Fix: return early when the requested size fits the current capacity, matching what string_impl::append already does; the two runs above then total 19.8 kB and 240 kB, with largest blocks of 6 kB and 48 kB.

@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1178.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-07-30 07:23:56 UTC

@cppalliance-bot

Copy link
Copy Markdown

GCOVR code coverage report https://1178.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1178.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1178.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-07-30 07:38:54 UTC

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.92%. Comparing base (6a57776) to head (a9b4402).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1178   +/-   ##
========================================
  Coverage    93.92%   93.92%           
========================================
  Files           91       91           
  Lines         9279     9285    +6     
========================================
+ Hits          8715     8721    +6     
  Misses         564      564           
Files with missing lines Coverage Δ
include/boost/json/detail/sbo_buffer.hpp 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a57776...a9b4402. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

Thank you for catching this.
Slightly changed and merged via 5779b03.

@grisumbras grisumbras closed this Jul 31, 2026
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.

3 participants