Skip to content

cmd/compile: increased compilation time for a parser package generated with goyacc #77011

@yuzefovich

Description

@yuzefovich

Go version

go version go1.25.5 linux/amd64

Output of go env in your module/workspace:

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='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/yahor_cockroachlabs_com/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/yahor_cockroachlabs_com/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build471937613=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/yahor_cockroachlabs_com/go/src/github.com/cockroachdb/cockroach/go.mod'
GOMODCACHE='/home/yahor_cockroachlabs_com/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/yahor_cockroachlabs_com/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/yahor_cockroachlabs_com/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.5.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/yahor_cockroachlabs_com/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/yahor_cockroachlabs_com/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.5.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

See below.

What did you see happen?

Over in CockroachDB we have a sql/parser package that mostly consists of the generated code from goyacc sql.go.zip. Over the last few years we noticed that the compilation time of this package has increased significantly with some new major Go releases. Part of it could be attributed to the growth of the package itself, but I believe most of the increase is due to some compiler work (which we do appreciate!).

Here are statistics I've gathered. Each bullet point compares compiling the same generated code but using different Go versions (the code across bullet points is different):

  • generated parser/sql.go file: 46954 lines
    • go 1.21.5: 18.8s
    • go 1.22.0: 22.9s
  • generated parser/sql.go file: 48952 lines
    • go 1.22.5: 26.5s
    • go 1.23.2: 26.8s
  • generated parser/sql.go file: 52343 lines
    • go 1.23.12: 38.3s
    • go 1.25.3: 34.6s (we by-passed go 1.24)
  • generated parser/sql.go file: 52642 lines (tip of master)
    • Go 1.25.5: 34.9s

Examining the debug-trace trace.zip we see that vast majority is spent building the package in a single thread

Image

Main observation

So overall, between 1.21.5 and 1.25.5 versions, while the code size increased by 12%, the build time increased by 86%. (The code generated by goyacc shouldn't have changed in a significant manner.)

What did you expect to see?

My hypothesis is that the shape of the generated parser code somehow doesn't play nicely with recent compiler improvements. I'd be curious to see whether improving compile time of such code is on the radar of the team. (Setting up the environment to build CockroachDB is a bit involved, so if there is interest, I could probably come up with a sample code as the benchmark.)

(Note that CockroachDB uses a fork of golang/go with a handful of patches on top that shouldn't impact the compile time.)

Metadata

Metadata

Assignees

No one assigned

    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.ToolSpeedcompiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions