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

go/types: audit memory usage for go1.17 #45580

Closed
findleyr opened this issue Apr 15, 2021 · 7 comments
Closed

go/types: audit memory usage for go1.17 #45580

findleyr opened this issue Apr 15, 2021 · 7 comments

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Apr 15, 2021

With the merging of the dev.typeparams branch, a number of the types in go/types picked up additional fields that are only used during the type checking pass. Many users of go/types (particularly gopls) are sensitive to the memory footprint of a type checked package. Filing this issue as a reminder for go1.17: we should verify that we're not pinning memory unnecessarily.

I did a quick check using both pprof and a memory debugging tool that @heschi is experimenting with for gopls, and they indicated that typechecked packages in go1.17 consume perhaps 5-10% more memory than in go1.16. We're not yet convinced that these are accurate numbers, but such a relative change is probably meaningful. If accurate, a 5-10% increase is not so bad, though we could probably eliminate it.

CC @griesemer

@findleyr findleyr added this to the Go1.17 milestone Apr 15, 2021
@findleyr findleyr self-assigned this Apr 15, 2021
@findleyr
Copy link
Contributor Author

@findleyr findleyr commented Apr 29, 2021

Marking this as a release blocker until we determine that any memory regressions are acceptable.

Loading

@toothrot
Copy link
Contributor

@toothrot toothrot commented May 6, 2021

@findleyr Checking in as this is a release-blocker. Is this acceptable to do after Beta 1?

Loading

@findleyr
Copy link
Contributor Author

@findleyr findleyr commented May 6, 2021

Thanks Alex!

This is okay after Beta 1, marked it accordingly. I expect we'll address this before Beta 1, though.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented May 11, 2021

Change https://golang.org/cl/318849 mentions this issue: go/types: ensure that Named.check is nilled out when it is completed

Loading

@findleyr
Copy link
Contributor Author

@findleyr findleyr commented May 11, 2021

Update: measured a couple ways, I was consistently seeing around a 6% increase in memory footprint when working on x/tools. CL 318849 should unpin the Checker, which in my testing almost exactly reclaimed the 6% regression.

I also tried externalizing object.color_ and object.order_ into maps, but this didn't seem to make much difference in memory footprint and slowed down the type checking pass by 2-4%. There may be something worth pursuing there, but not for 1.17.

Loading

@gopherbot gopherbot closed this in 39da9ae May 26, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented May 27, 2021

Change https://golang.org/cl/323030 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: ensure that Named.check is nilled out once it is expanded

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented May 27, 2021

Change https://golang.org/cl/322974 mentions this issue: go/types: guard against check==nil in newNamed

Loading

gopherbot pushed a commit that referenced this issue May 27, 2021
When importing generic named types, it is possible for Checker.newNamed
to be called during type instantiation when the Checker is nil.

In this case we should be able to safely skip this delayed expansion.

Updates #45580

Change-Id: I75422100464d57eba24642c93e06e8b47d904fc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/322974
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopherbot pushed a commit that referenced this issue May 27, 2021
… is nilled out once it is expanded

This is a port of
- https://golang.org/cl/318849
- https://golang.org/cl/322974

For #45580.

Change-Id: Ie0700ed6c8d472305d5ba7ff97da1ae063152aa3
Reviewed-on: https://go-review.googlesource.com/c/go/+/323030
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants