Skip to content

cmd/compile: optimize append([]byte(string), ...) to avoid a duplication #47454

@zigo101

Description

@zigo101

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

$ go version
go version go1.17rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import "testing"

var str = "1234567890123456789012345678901234567890"

func f() {
	_ = append([]byte(str), str...)
}

func main() {
	stat := func( f func() ) int {
		allocs := testing.AllocsPerRun(1, f)
		return int(allocs)
	}
	println(stat(f)) // 2
}

What did you expect to see?

One allocation.

What did you see instead?

Two instead.

The allocation for []byte(str) could be saved.

Partially related to #43429.

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