Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: cyclic interfaces cause massive memory usage #35146

Closed
elagergren-spideroak opened this issue Oct 25, 2019 · 8 comments
Closed

cmd/compile: cyclic interfaces cause massive memory usage #35146

elagergren-spideroak opened this issue Oct 25, 2019 · 8 comments

Comments

@elagergren-spideroak
Copy link

@elagergren-spideroak elagergren-spideroak commented Oct 25, 2019

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

$ go version
go version go1.13.1 darwin/amd64

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/elagergren/gopath/bin"
GOCACHE="/Users/elagergren/Library/Caches/go-build"
GOENV="/Users/elagergren/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/elagergren/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2b/74fz3jhd4wz4vnbf4z7ywzww0000gp/T/go-build398016473=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/3-RUQ50ubib

What did you expect to see?

Something other than compile ballooning to over 6 GB of RAM.

Maybe relates to #27256 and #26863.

@elagergren-spideroak

This comment has been minimized.

Copy link
Author

@elagergren-spideroak elagergren-spideroak commented Oct 25, 2019

@mdempsky

This comment has been minimized.

Copy link
Member

@mdempsky mdempsky commented Oct 25, 2019

Interesting. If I had to guess, we're probably failing to take advantage of memoizing some of the sub-expression typechecking. In general though, anonymous and cyclic interfaces are a recurring source of issues.

Is this derived from any real world code?

@elagergren-spideroak

This comment has been minimized.

Copy link
Author

@elagergren-spideroak elagergren-spideroak commented Oct 25, 2019

Believe it or not. It's from (rudimentary) SQL generator. The anonymous interfaces are used to "mask" off methods. It's not terribly important code, but it also wasn't difficult to stumble upon, either.

A smaller repro:

https://play.golang.org/p/PoFq8QTuiMp

type A interface {
   A() interface {
      A
      B() interface{ A }
   }
}
@elagergren-spideroak

This comment has been minimized.

Copy link
Author

@elagergren-spideroak elagergren-spideroak commented Oct 25, 2019

Even smaller:

https://play.golang.org/p/Yoll2YkmZNS

type A interface {
   A() interface{ A }
   B() interface{ A }
}
@mdempsky

This comment has been minimized.

Copy link
Member

@mdempsky mdempsky commented Oct 25, 2019

Thanks for minimizing the test case.

To clarify, are you saying it uses a lot of memory but then terminates? Or it's going into an infinite loop allocating more and more memory?

(On my phone, and the play links just give a generic compilation failure error.)

@ALTree

This comment has been minimized.

Copy link
Member

@ALTree ALTree commented Oct 25, 2019

This looks like #1909.

@elagergren-spideroak

This comment has been minimized.

Copy link
Author

@elagergren-spideroak elagergren-spideroak commented Oct 25, 2019

@mdempsky I cut it off at > 6 GB since my machine only has 8GB. No idea whether it terminates.

@mdempsky

This comment has been minimized.

Copy link
Member

@mdempsky mdempsky commented Oct 25, 2019

@ALTree Thanks, confirmed it is a dup of that. We just go into an infinite recursion in typefmt.

@elagergren-spideroak Thanks for clarifying.

@mdempsky mdempsky closed this Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.