Skip to content

strings: (*Builder).Grow should take benefit from sizeclasses #64833

Closed

Description

@mateusz834

The Grow method on strings.Builder is documented as:

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

Currently it grows as such:

// grow copies the buffer to a new, larger buffer so that there are at least n
// bytes of capacity beyond len(b.buf).
func (b *Builder) grow(n int) {
	buf := bytealg.MakeNoZero(2*cap(b.buf) + n)[:len(b.buf)]
	copy(buf, b.buf)
	b.buf = buf
}

I think that it is backwards compatible to start using sizeclasses in the strings.Builder, and not waste memory while growing.

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Dec 21, 2023
  2. added this to the Backlog milestone on Dec 21, 2023
  3. self-assigned this
    on Dec 21, 2023
  4. changed the title [-]strings: strings.Builder.Grow should take benefit from sizeclasses[/-] [+]strings: strings.Builder Grow should take benefit from sizeclasses[/+] on Dec 21, 2023
  5. changed the title [-]strings: strings.Builder Grow should take benefit from sizeclasses[/-] [+]strings: (*Builder).Grow should take benefit from sizeclasses[/+] on Dec 21, 2023
  6. gopherbot commented on Dec 21, 2023

    @gopherbot
    Contributor

    Change https://go.dev/cl/552135 mentions this issue: strings: make use of sizeclasses in (*Builder).Grow

  7. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Jan 2, 2024
  8. modified the milestones: Backlog, Go1.23 on Jan 2, 2024
  9. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jan 2, 2024
  10. added a commit that references this issue on Feb 19, 2024
    968b71b
  11. locked and limited conversation to collaborators on Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions