Skip to content

Go

Concepts 11 posts

Go goroutine leaks and pprofchannels, mutexes, and exit paths

Starting a goroutine is easy. The hard part was deciding who changes the data, who finishes the work, and when a function may return.

Go sync.Pool and buffer reuseafter Put, Bytes() isn't yours

In the previous post, total allocations stayed at 256MiB however I set GOGC and GOMEMLIMIT. Reusing short-lived buffers with sync.Pool is one way to shrink it.

Go GOMEMLIMIT and GOGCOOMKilled with an 800MB heap

The container limit was 1GB, yet the process was OOMKilled with an 800MB heap. Go has a garbage collector, so how did memory run out?

Go GMP and GOMAXPROCScontainer CPU limits and goroutines

Put go in front of a call and it runs concurrently. So do 100,000 goroutines mean 100,000 threads? Does GOMAXPROCS=1 mean one task at a time?

Copying structs in Gowhy a shallow copy changes the map too

Interfaces, slices, defer, embedding, context: looking back after five posts, most of the pitfalls came from two axes. One is "everything is copied"; the other is "object orientation without classes."

Go context, fully explainedcancellation, time budgets, and four pitfalls

I was already taking ctx as the first argument and passing it along. What I had never checked was whether canceling actually stops the goroutine. After stalling on that question in an interview, I went back to context from the start.

Why Go has no inheritancerebuilding OOP with embedding and interfaces

Go has no classes and no inheritance, yet it's hard to call it non-object-oriented. The official FAQ answers "Is Go an object-oriented language?" with "Yes and no." This post explains why by following what Go put where inheritance used to be.

Go defer, Errors, and ClosuresLIFO, Error Wrapping, and the Loop Variable Trap

Go dropped exceptions and filled the gap with defer and errors as values. All three take seconds to learn and keep producing traps for years. I reorganized them around one question: exactly when, and what, does each one hold on to?

Why Go's append Changes the OriginalInside Slices, Maps, and Strings

The Go bugs I keep hitting come from holding something different from what I think I'm holding. A slice is a window, not data. A map doesn't guarantee addresses. A string isn't a character array. This post opens up the layout of all three.

esc

Recent posts

↑↓ move↵ openOpen search page ›