This might be a silly question or too open-ended, but what do I look for in GHC core output to understand where memory allocations are happening? My motivation is to better understand how to optimize code like this, or e.g. to try to avoid preemption during critical sections in concurrent code.
Stack and Heap The Common Language Runtime (CLR) allocates memory for objects in these parts. Stack is a simple LIFO(last-in-first-out) structure. Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and its allocation is done when the program is compiled.
pprof and flame graphs are pretty useful to analyze application memory leaks. A continuous profiler can really help you look at multiple snapshots of the profile and quickly figure out the cause of leaks. Cloud profiler is definitely a handy tool for GCP workloads.
The only thing you need to do is import net/http/pprof and start an http listener. The pprof package will register its endpoints right below the web server root at /debug/pprof. In order to analyze the currently used memory, just select the inuse indices (bytes or object counts):
let
s is typically where this happens, assuming the variable being bounds id not of kind #
(i.e. a let-bound Int#
doesn't cause allocation.) However, it's really STG which defines exactly where it happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With