[go] runtime,cmd/compile: specialize growslice for strings

7 views
Skip to first unread message

Egon Elbre (Gerrit)

unread,
May 23, 2023, 6:20:59 AM5/23/23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Set Ready For Review

View Change

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Comment-Date: Tue, 23 May 2023 10:20:55 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No

    Martin Möhrmann (Gerrit)

    unread,
    May 23, 2023, 6:41:59 AM5/23/23
    to Egon Elbre, goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Egon Elbre, Keith Randall, Robert Griesemer.

    View Change

    2 comments:

    • Patchset:

      • Patch Set #2:

        I dont see added tests in all these cls. Can we make sure every one of these specialized functions is as well tested as the more general growslice function was before?

    • File src/runtime/slice.go:

      • Patch Set #2, Line 315: // growslicestr is a specialized function of growslice for []string.

        Its unfortunate we are duplicating alot of boilerplate for all these specialized functions. maybe we can further share parts of it if we really want to go further down this route:

        e.g.

        if raceenabled || msanenabled || asanenabled {
        dosanchecks(...)
        }

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Egon Elbre <egon...@gmail.com>
    Gerrit-Comment-Date: Tue, 23 May 2023 10:41:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No

    Egon Elbre (Gerrit)

    unread,
    May 23, 2023, 6:46:55 AM5/23/23
    to goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Martin Möhrmann, Robert Griesemer.

    View Change

    2 comments:

    • Patchset:

      • Patch Set #2:

        I dont see added tests in all these cls. […]

        Sure. Currently there exist tests for `[]string` already, but I can definitely add more.

        I guess one question is whether all of them improve sufficiently.

    • File src/runtime/slice.go:

      • Its unfortunate we are duplicating alot of boilerplate for all these specialized functions. […]

        Ah, yes, that would be better.

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Tue, 23 May 2023 10:46:51 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Martin Möhrmann <moeh...@google.com>

    Martin Möhrmann (Gerrit)

    unread,
    May 23, 2023, 7:58:30 AM5/23/23
    to Egon Elbre, goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Egon Elbre, Keith Randall, Robert Griesemer.

    View Change

    2 comments:

    • Patchset:

      • Patch Set #2:

        Sure. Currently there exist tests for `[]string` already, but I can definitely add more. […]

        I havent checked but I remember there were test to test correct overflow behaviour and such. I would be worried that the coverage is going to reduce for edge cases like 0 elements, overflow, ... .

    • File src/runtime/slice.go:

      • Ah, yes, that would be better.

        In general I think there might be room for a better code duplication to performance gain tradeoff. There is some room for performance improvement here for sure, but I worry about two things: longterm maintainability, issues like icache usage if we start specializing every function in the runtime to types. Which is the reason I considered this in the past but ultimately thought I rather keep the code in one place and shared.

        I have not explored this but maybe we could get most (certainly not all) of the performance increase by only creating wrappers and 1-2 still generic functions as core.

        e.g.

        growslicestr(...) slice {
        return growsliceinternal(..., strgrowcalc)
        }
        growslicebyte(...) slice {
        return growsliceinternal(..., bytegrowcalc)
        }

        where strgrowcalc are the specialized functions to avoid some dispatch overhead in the right oldmem, lenmem, capmem ... calculations. At least that can then share more code and we can fill in the consts for et_ptrbytes and et_size ... in the wrappers as consts which migh avoid some data loads. Argument order could matter to make sure as much register moves are avoided as possible.

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Egon Elbre <egon...@gmail.com>
    Gerrit-Comment-Date: Tue, 23 May 2023 11:58:25 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Martin Möhrmann <moeh...@google.com>
    Comment-In-Reply-To: Egon Elbre <egon...@gmail.com>

    Egon Elbre (Gerrit)

    unread,
    May 23, 2023, 8:03:19 AM5/23/23
    to goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Martin Möhrmann, Robert Griesemer.

    View Change

    1 comment:

    • File src/runtime/slice.go:

      • but I worry about two things: longterm maintainability, issues like icache usage if we start specializing every function in the runtime to types. Which is the reason I considered this in the past but ultimately thought I rather keep the code in one place and shared.

        Same here, but I wasn't able to come up with a better approach while writing it.

      • growslicestr(...) slice {
        return growsliceinternal(..., strgrowcalc)

      • Yes, that could be better.

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Tue, 23 May 2023 12:03:14 +0000

    Egon Elbre (Gerrit)

    unread,
    May 23, 2023, 9:11:41 AM5/23/23
    to goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Martin Möhrmann, Robert Griesemer.

    View Change

    1 comment:

    • File src/runtime/slice.go:

      • > but I worry about two things: longterm maintainability, issues like icache usage if we start speci […]

        Oh, one thing I realized.

        The `num` argument is only needed due to sanitizers, but the cost of extra argument exists even when all of them are disabled. I'm now wondering whether it's possible to only need that argument when race is enabled. One option is to generate the sanitizer outside of growslice; the other is to create a `growslicesan` and select the implementation depending on whether sanitizers are implemented. Maybe there's some additional way?

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Comment-Date: Tue, 23 May 2023 13:11:37 +0000

    Robert Griesemer (Gerrit)

    unread,
    May 23, 2023, 12:02:23 PM5/23/23
    to Egon Elbre, goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Martin Möhrmann.

    Robert Griesemer removed Robert Griesemer from this change.

    View Change

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: deleteReviewer
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>

    Keith Randall (Gerrit)

    unread,
    May 23, 2023, 1:12:22 PM5/23/23
    to Egon Elbre, goph...@pubsubhelper.golang.org, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Egon Elbre, Martin Möhrmann.

    Patch set 2:Code-Review +2

    View Change

    2 comments:

    • File src/cmd/compile/internal/ssa/_gen/generic.rules:

      • Patch Set #2, Line 2621: isSameCall(sym, "runtime.growslicebyte")

        I think you could do (isSameCall(sym, "runtime.growslicebyte") || isSameCall(sym, "runtimne.growslicestr")).
        And maybe make the rule multi-line, it is kind of long as it is.

    • File src/cmd/compile/internal/ssagen/ssa.go:

      • Patch Set #2, Line 3470: case et.Kind() == types.TSTRING:

        I wonder if we could use this path for anything "string-ish", for example:

        type S struct { p *int, n int }

        That could use growslicestr even though it isn't a string.

        Definitely not for this CL though, just pondering future improvements.

    To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
    Gerrit-Change-Number: 496141
    Gerrit-PatchSet: 2
    Gerrit-Owner: Egon Elbre <egon...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Attention: Egon Elbre <egon...@gmail.com>
    Gerrit-Comment-Date: Tue, 23 May 2023 17:12:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes

    Keith Randall (Gerrit)

    unread,
    May 23, 2023, 1:12:37 PM5/23/23
    to Egon Elbre, goph...@pubsubhelper.golang.org, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Egon Elbre, Martin Möhrmann.

    Patch set 2:Code-Review +1

    View Change

      To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
      Gerrit-Change-Number: 496141
      Gerrit-PatchSet: 2
      Gerrit-Owner: Egon Elbre <egon...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Egon Elbre <egon...@gmail.com>
      Gerrit-Comment-Date: Tue, 23 May 2023 17:12:34 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes

      Keith Randall (Gerrit)

      unread,
      May 23, 2023, 1:13:23 PM5/23/23
      to Egon Elbre, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Egon Elbre, Martin Möhrmann.

      View Change

      1 comment:

      • Patchset:

        • Patch Set #2:

          Not sure if you intend to get these in for 1.21 or not, but the schedule is pretty tight at the moment...

      To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
      Gerrit-Change-Number: 496141
      Gerrit-PatchSet: 2
      Gerrit-Owner: Egon Elbre <egon...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Egon Elbre <egon...@gmail.com>
      Gerrit-Comment-Date: Tue, 23 May 2023 17:13:20 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No

      Egon Elbre (Gerrit)

      unread,
      May 23, 2023, 1:33:53 PM5/23/23
      to goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Martin Möhrmann.

      View Change

      2 comments:

      • Patchset:

        • Patch Set #2:

          Not sure if you intend to get these in for 1. […]

          There's no rush with these changes. I just accidentally ended pushing them just before the freeze.

      • File src/cmd/compile/internal/ssagen/ssa.go:

        • I wonder if we could use this path for anything "string-ish", for example: […]

          Currently `mallocgc` inside `growslice` requires the exact type as the argument. I'm not sure whether it's sufficient for it to be the same shape or should it be the exact type.

      To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
      Gerrit-Change-Number: 496141
      Gerrit-PatchSet: 2
      Gerrit-Owner: Egon Elbre <egon...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Comment-Date: Tue, 23 May 2023 17:33:48 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Keith Randall <k...@golang.org>

      Keith Randall (Gerrit)

      unread,
      May 23, 2023, 1:44:57 PM5/23/23
      to Egon Elbre, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Egon Elbre, Martin Möhrmann.

      View Change

      1 comment:

      • File src/cmd/compile/internal/ssagen/ssa.go:

        • Currently `mallocgc` inside `growslice` requires the exact type as the argument. […]

          mallocgc only cares about the size, alignment, and pointerness of fields. So anything that looks like a string in its layout would work fine using mallocgc(n, stringType, true).
          The one exception is the allocation tracer, but that's a GODEBUG setting and would be fine if the two were conflated in allocation traces.
          At least, currently. Maybe someday we'll have object headers with full type info for all objects in the heap and the distinction might matter more. I'm not worried about it though.

      To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
      Gerrit-Change-Number: 496141
      Gerrit-PatchSet: 2
      Gerrit-Owner: Egon Elbre <egon...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Egon Elbre <egon...@gmail.com>
      Gerrit-Comment-Date: Tue, 23 May 2023 17:44:53 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      Comment-In-Reply-To: Egon Elbre <egon...@gmail.com>

      Matthew Dempsky (Gerrit)

      unread,
      May 23, 2023, 4:12:08 PM5/23/23
      to Egon Elbre, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com

      Attention is currently required from: Egon Elbre, Martin Möhrmann.

      Patch set 2:Code-Review +1

      View Change

        To view, visit change 496141. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
        Gerrit-Change-Number: 496141
        Gerrit-PatchSet: 2
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: Egon Elbre <egon...@gmail.com>
        Gerrit-Comment-Date: Tue, 23 May 2023 20:12:04 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes

        Egon Elbre (Gerrit)

        unread,
        Aug 11, 2026, 10:31:18 AM (17 hours ago) Aug 11
        to goph...@pubsubhelper.golang.org, Matthew Dempsky, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Keith Randall, Keith Randall, Martin Möhrmann and Matthew Dempsky

        Egon Elbre added 3 comments

        Patchset-level comments
        File-level comment, Patchset 2:
        Martin Möhrmann . resolved

        I dont see added tests in all these cls. Can we make sure every one of these specialized functions is as well tested as the more general growslice function was before?

        Egon Elbre

        Sure. Currently there exist tests for `[]string` already, but I can definitely add more.

        I guess one question is whether all of them improve sufficiently.

        Martin Möhrmann

        I havent checked but I remember there were test to test correct overflow behaviour and such. I would be worried that the coverage is going to reduce for edge cases like 0 elements, overflow, ... .

        Egon Elbre

        I added some more tests, not sure whether it's sufficient now.

        File src/cmd/compile/internal/ssa/_gen/generic.rules
        Line 2621, Patchset 2:(SliceLen (SelectN [0] (StaticLECall {sym} _ newLen:(Const(64|32)) _ _ _))) && isSameCall(sym, "runtime.growslicebyte") => newLen
        Keith Randall . resolved

        I think you could do (isSameCall(sym, "runtime.growslicebyte") || isSameCall(sym, "runtimne.growslicestr")).
        And maybe make the rule multi-line, it is kind of long as it is.

        Egon Elbre

        I ended up adding `isGrowSlice` in https://go-review.googlesource.com/c/go/+/495878 in

        File src/runtime/slice.go
        Line 315, Patchset 2:// growslicestr is a specialized function of growslice for []string.
        Martin Möhrmann . resolved

        Its unfortunate we are duplicating alot of boilerplate for all these specialized functions. maybe we can further share parts of it if we really want to go further down this route:

        e.g.

        if raceenabled || msanenabled || asanenabled {
        dosanchecks(...)
        }
        Egon Elbre

        Ah, yes, that would be better.

        Martin Möhrmann

        In general I think there might be room for a better code duplication to performance gain tradeoff. There is some room for performance improvement here for sure, but I worry about two things: longterm maintainability, issues like icache usage if we start specializing every function in the runtime to types. Which is the reason I considered this in the past but ultimately thought I rather keep the code in one place and shared.

        I have not explored this but maybe we could get most (certainly not all) of the performance increase by only creating wrappers and 1-2 still generic functions as core.

        e.g.

        growslicestr(...) slice {
        return growsliceinternal(..., strgrowcalc)
        }
        growslicebyte(...) slice {
        return growsliceinternal(..., bytegrowcalc)
        }

        where strgrowcalc are the specialized functions to avoid some dispatch overhead in the right oldmem, lenmem, capmem ... calculations. At least that can then share more code and we can fill in the consts for et_ptrbytes and et_size ... in the wrappers as consts which migh avoid some data loads. Argument order could matter to make sure as much register moves are avoided as possible.

        Egon Elbre

        but I worry about two things: longterm maintainability, issues like icache usage if we start specializing every function in the runtime to types. Which is the reason I considered this in the past but ultimately thought I rather keep the code in one place and shared.

        Same here, but I wasn't able to come up with a better approach while writing it.

        growslicestr(...) slice {
        return growsliceinternal(..., strgrowcalc)

        Yes, that could be better.

        Egon Elbre

        Oh, one thing I realized.

        The `num` argument is only needed due to sanitizers, but the cost of extra argument exists even when all of them are disabled. I'm now wondering whether it's possible to only need that argument when race is enabled. One option is to generate the sanitizer outside of growslice; the other is to create a `growslicesan` and select the implementation depending on whether sanitizers are implemented. Maybe there's some additional way?

        Egon Elbre

        Finally came back to this change; it was possible to share the san logic, which was implemented in https://go-review.googlesource.com/c/go/+/813020 and https://go-review.googlesource.com/c/go/+/495878 also was able to share a lot of logic.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keith Randall
        • Keith Randall
        • Martin Möhrmann
        • Matthew Dempsky
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
        Gerrit-Change-Number: 496141
        Gerrit-PatchSet: 11
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Matthew Dempsky <mdem...@google.com>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: Keith Randall <k...@google.com>
        Gerrit-Comment-Date: Tue, 11 Aug 2026 14:31:05 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Keith Randall <k...@golang.org>
        Comment-In-Reply-To: Egon Elbre <egon...@gmail.com>
        Comment-In-Reply-To: Martin Möhrmann <moeh...@google.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        t hepudds (Gerrit)

        unread,
        Aug 11, 2026, 1:20:40 PM (14 hours ago) Aug 11
        to Egon Elbre, goph...@pubsubhelper.golang.org, Matthew Dempsky, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Egon Elbre, Keith Randall, Keith Randall, Martin Möhrmann and Matthew Dempsky

        t hepudds voted Commit-Queue+1

        Commit-Queue+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Egon Elbre
        • Keith Randall
        • Keith Randall
        • Martin Möhrmann
        • Matthew Dempsky
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
        Gerrit-Change-Number: 496141
        Gerrit-PatchSet: 11
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Matthew Dempsky <mdem...@google.com>
        Gerrit-Attention: Egon Elbre <egon...@gmail.com>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: Keith Randall <k...@google.com>
        Gerrit-Comment-Date: Tue, 11 Aug 2026 17:20:35 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Egon Elbre (Gerrit)

        unread,
        Aug 11, 2026, 2:51:14 PM (13 hours ago) Aug 11
        to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, t hepudds, Matthew Dempsky, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Keith Randall, Keith Randall, Martin Möhrmann, Matthew Dempsky and t hepudds

        Egon Elbre voted Commit-Queue+1

        Commit-Queue+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keith Randall
        • Keith Randall
        • Martin Möhrmann
        • Matthew Dempsky
        • t hepudds
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
        Gerrit-Change-Number: 496141
        Gerrit-PatchSet: 12
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Matthew Dempsky <mdem...@google.com>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: t hepudds <thepud...@gmail.com>
        Gerrit-Attention: Keith Randall <k...@google.com>
        Gerrit-Comment-Date: Tue, 11 Aug 2026 18:51:06 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Egon Elbre (Gerrit)

        unread,
        12:57 AM (3 hours ago) 12:57 AM
        to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, t hepudds, Matthew Dempsky, Keith Randall, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Keith Randall, Keith Randall, Martin Möhrmann, Matthew Dempsky and t hepudds

        Egon Elbre voted Commit-Queue+1

        Commit-Queue+1
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keith Randall
        • Keith Randall
        • Martin Möhrmann
        • Matthew Dempsky
        • t hepudds
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I3178c61dfedbd4f0cd0ab5406fa9f075136a8535
        Gerrit-Change-Number: 496141
        Gerrit-PatchSet: 14
        Gerrit-Owner: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Egon Elbre <egon...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
        Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Matthew Dempsky <mdem...@google.com>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: t hepudds <thepud...@gmail.com>
        Gerrit-Attention: Keith Randall <k...@google.com>
        Gerrit-Comment-Date: Wed, 12 Aug 2026 04:57:49 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages