As compared to the other runtimes, Go is quite memory

Arpit Bhayani

Arpit Bhayani

Oct 29, 2023 • 1 min read


As compared to the other runtimes, Go is quite memory efficient; here’s the secret sauce ⚡

Go uses a compiler optimization called escape analysis which helps optimize memory usage. The key idea of this optimization technique is to analyze the code and understand if an object escapes the current scope.

If the object escapes the current scope, allocate them on the heap, otherwise go for the stack. Given that stack-allocated objects are automatically cleaned up when the function returns, it prevents memory leaks and minimizes the work required by the GC.

To understand this and more, read the comment mentioned in the attached file. Also, you can use -gcflags "-m" while running go build and it would print all the optimization decisions.

ref: https://lnkd.in/givNEABH

⚡ To understand Redis Internals check out my course on Redis Internals where I have talked about these algorithms and have re-implemented all key features in Golang

arpitbhayani.me/redis

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses