Skip to content

slices: Concat allocates more than requested #70935

@adonovan

Description

@adonovan

slices.Concat calls Grow(nil, size), which rounds up the capacity allocation using append's heuristic. For example, the slice returned by Concat may have len=1000 but cap=1023. Is this intentional? I would have thought that slices.Concat is often called when the exact final size is known and no further appends are intended, making this extra allocation wasteful.

Is the idea that rounding up to the size class is essentially free, and avoids reallocation in the not uncommon case that a single element or small handful of elements are added to the end of a large slice.Concat? If so, a comment would be appreciated.

Metadata

Metadata

Assignees

Labels

DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions