Skip to content

runtime: significant number of bounds checks in growslice #60071

@egonelbre

Description

@egonelbre

While inspecting the runtime.growslice code I noticed that it contains a lot of bounds checks. They all come from runtime.roundupsize.

What version of Go are you using (go version)?

$ go version
go version devel go1.21-8d5065ce6e Tue May 9 11:45:59 2023 +0300 windows/amd64

However also happens with go1.20.4.

Does this issue reproduce with the latest release?

Yes and with tip.

What did you do?

Inspecting runtime.growslice and seeing:

$ go tool objdump -s runtime.growslice ./somebinary
...
  0x445f0f              488d052a320500          LEAQ type:*+45376(SB), AX
  0x445f16              488d1dfb3c0800          LEAQ runtime.buildVersion.str+720(SB), BX
  0x445f1d              0f1f00                  NOPL 0(AX)
  0x445f20              e87bd0feff              CALL runtime.gopanic(SB)
                        return uintptr(class_to_size[size_to_class128[divRoundUp(size-smallSizeMax, largeSizeDiv)]])
  0x445f25              b944000000              MOVL $0x44, CX
  0x445f2a              e891860100              CALL runtime.panicIndex(SB)
  0x445f2f              b9f9000000              MOVL $0xf9, CX
  0x445f34              e8a7860100              CALL runtime.panicIndexU(SB)
                        return uintptr(class_to_size[size_to_class8[divRoundUp(size, smallSizeDiv)]])
  0x445f39              b944000000              MOVL $0x44, CX
  0x445f3e              6690                    NOPW
  0x445f40              e87b860100              CALL runtime.panicIndex(SB)
  0x445f45              b981000000              MOVL $0x81, CX
  0x445f4a              e891860100              CALL runtime.panicIndexU(SB)
                        return uintptr(class_to_size[size_to_class128[divRoundUp(size-smallSizeMax, largeSizeDiv)]])
...

What did you expect to see?

I'm not sure how much they affect performance, but triggering that many in roundupsize does seem a bit concerning.


I tried to do the trivial patch with zero-filling the tables to exactly 256 elements https://go-review.googlesource.com/c/go/+/493796, however, I'm not convinced that this is the best way to address this. Either way, I'm willing to take a stab at fixing it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions