runtime: significant heap profiler memory usage increase in Go 1.23 #69590
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go1.23.1
Output of
go env
in your module/workspace:What did you do?
We upgraded our Go services to Go 1.23.1. All of our services use continuous profiling and have the heap profiler enabled. Go 1.23 increased the default call stack depth for the heap profiler (and others) from 32 frames to 128 frames.
What did you see happen?
We saw a significant increase in memory usage for one of our services, in particular the
/memory/classes/profiling/buckets:bytes
runtime metric:The maximum went from ~50MiB to almost 4GiB, an 80x increase. We also saw a significant increase in the time to serialize the heap profile, from <1 second to over 20 seconds.
We set the environment variable
GODEBUG=profstackdepth=32
to get the old limit, and the profiling bucket memory usage went back down.What did you expect to see?
We were surprised at first to see such a significant memory usage increase. However, the affected program is doing just about the worst-case thing for the heap profiler. It parses complex, deeply-nested XML. This results in a massive number of unique, deep stack traces due to the mutual recursion in the XML parser. And the heap profiler never frees any stack trace it collects, so the cumulative size of the buckets becomes significant as more and more unique stack traces are observed.
See this gist for a (kind of kludgy) example program which sees a 100x increase in bucket size from Go 1.22 to Go 1.23.
I'm mainly filing this issue to document this behavior. Manually setting
GODEBUG=profstackdepth=32
mitigates the issue. I don't think anything necessarily needs to change in the runtime right now, unless this turns out to be a widespread problem.cc @felixge
The text was updated successfully, but these errors were encountered: