79356841

Date: 2025-01-15 01:41:49
Score: 0.5
Natty:
Report link

A more anecdotal answer than @evanmcdonnal's is that, at least in go1.22,

package main

import "fmt"

const (
    str1 = "asdf"
    str2 = "ghjk"
)

func main() {
    fmt.Println(str1, str2)
}

and

package main

import "fmt"

const (
    str1 = "asdf"
    str2 = "asdf"
)

func main() {
    fmt.Println(str1, str2)
}

compile out to the same size. So the compiler doesn't even optimize that within the same file.

$ go version
go version go1.22.2 darwin/arm64
$ go build -o diff diff.go
$ go build -o same same.go
$ ls -l
total 7952
...  2029586 Jan 14 17:32 diff
...      110 Jan 14 17:31 diff.go
...  2029586 Jan 14 17:32 same
...      110 Jan 14 17:31 same.go
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @evanmcdonnal's
  • Low reputation (0.5):
Posted by: thisisbenmanley