[GODRIVER-2025] Always reuse buffers in bsonrw.valueWriter Created: 25/May/21 Updated: 25/Jul/22 Resolved: 14/Jun/21 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.6.0 |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Matt Dale | Assignee: | Matt Dale |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Epic Link: | Reduce Allocations | ||||||||
| Quarter: | FY23Q2, FY23Q3 | ||||||||
| Description |
|
Currently, a bsonrw.valueWriter will use a new byte slice as the write buffer for each document written if one is passed in as the writer (if it is a SliceWriter). The result is that the write buffer capacity must be grown many times, each resulting in an allocate-then-copy operation. Instead, we should reuse the write buffer for every document written, only allocating a new byte slice when flushing the full document from the buffer (or when the write buffer needs to grow). In the attached memory profile, observe that >75% of the allocations are in the bsoncore.Append* functions which append to a byte slice buffer provided by bsonrw.valueWriter. We should expect very few allocations in the bsoncore.Append* functions once the buffer is grown the first time. |
| Comments |
| Comment by Githook User [ 14/Jun/21 ] |
|
Author: {'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}Message: |
| Comment by Matt Dale [ 27/May/21 ] |