Skip to content

cmd/compile: CSE has quadratic running time #77506

Description

@Jorropo
Details

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

$ go version
go version go1.27-devel_9777ceceec Sat Feb 7 15:11:25 2026 -0800 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/tmp/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/hugo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1000996818=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/hugo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/hugo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/hugo/k/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/hugo/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/hugo/k/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.27-devel_9777ceceec Sat Feb 7 15:11:25 2026 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'
GOROOT/bin/go version: go version go1.27-devel_9777ceceec Sat Feb 7 15:11:25 2026 -0800 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.27-devel_9777ceceec Sat Feb 7 15:11:25 2026 -0800
uname -sr: Linux 6.18.7-arch1-1
LSB Version:	n/a
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.42.
lldb --version: lldb version 21.1.6
gdb --version: GNU gdb (GDB) 17.1

What did you do?

Here is a script generating a minimized example:

// /tmp/a.go
package main

import "os"
import "bufio"
import "strconv"

func run() error {
	iterations, err := strconv.ParseUint(os.Args[1], 10, 64)
	if err != nil {
		return err
	}

	f, err := os.Create("/tmp/result.go")
	if err != nil {
		return err
	}
	defer f.Close()

	w := bufio.NewWriter(f)
	w.WriteString(`package a

type T *T

func a(n T) T {
`)
	for range iterations {
		w.WriteString("\tn = *n\n")
	}
	w.WriteString(`	return n
}
`)
	err = w.Flush()
	if err != nil {
		return err
	}

	err = f.Close()
	if err != nil {
		return err
	}
	return nil
}

func main() {
	if err := run(); err != nil {
		os.Stderr.WriteString(err.Error())
		os.Exit(1)
	}
	os.Exit(0)
}

Example of the result.go program with go run a.go 5:

package a

type T *T

func a(n T) T {
	n = *n
	n = *n
	n = *n
	n = *n
	n = *n
	return n
}

Bug repro:

> go run a.go 10000
> time go build results.go

What did you expect to see?

Compilation finishes quickly (maybe a second or two).

What did you see instead?

Compilation scales poorly:

Image

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions