You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
148974: util/bufalloc: fix misuse and improve ByteAllocator API r=yuzefovich a=yuzefovich
**kvserver/gc,rowcontainer: fix misuse of ByteAllocator API**
`bufalloc.ByteAllocator.Copy` has an option to allocate extra capacity,
meaning that it copies the passed-in byte slice into a new memory region
while also adding extra capacity to be utilized by caller. Crucially,
that extra capacity lives in the returned byte slice containing the
copy. We use this feature in two places throughout the codebase, and in
both places it was used incorrectly, resulting in a wasteful allocation.
Consider the following setup:
k = [1, 2], v = [3, 4, 5, 6]
With invocation like `alloc, k = alloc.Copy(k, len(v))`, we would get
len(k) = 2, cap(k) = 6
However, in both spots we copied `v` via `alloc, v = alloc.Copy(v, 0)`,
which would actually create another allocation.
This commit fixes this oversight (both were introduced in 2022 by different
authors), and the following commit will clean up the API to avoid possible
confusion.
Informs: #147601.
**util/bufalloc: clean up ByteAllocator API**
`bufalloc.ByteAllocator`, as evidenced by a fix in the previous commit,
has confusing API for allocating "extra capacity". This commit cleans it up
by removing the option altogether. The only two spots that utilized the
extra capacity previously now explicitly request combined allocated
upfront and manage the copying behavior.
Release note: None
Co-authored-by: Yahor Yuzefovich <[email protected]>
0 commit comments