Skip to content Skip to footer

Go Optimization Guide by jedeusus

11 Comments

  • Post Author
    parhamn
    Posted March 31, 2025 at 10:19 pm

    Noticed the object pooling doc, had me wondering: are there any plans to make packages like `sync` generic?

  • Post Author
    roundup
    Posted March 31, 2025 at 10:32 pm

    Additionally…

    https://go101.org/optimizations/101.html

    https://github.com/uber-go/guide

    I wish this content existed as a model context protocol (MCP) tool to connect to my IDE along w/ local LLM.

    After 6 months or switching between different language projects, it's challenging to remember all the important things.

  • Post Author
    nopurpose
    Posted March 31, 2025 at 10:34 pm

    Every perf guide recommends to minimize allocations to reduce GC times, but if you look at pprof of a Go app, GC mark phase is what takes time, not GC sweep. GC mark always starts with known live roots (goroutine stacks, globals, etc) and traverse references from there colouring every pointer. To minimize GC time it is best to avoid _long living_ allocations. Short lived allocations, those which GC mark phase will never reach, has almost neglible effect on GC times.

    Allocations of any kind have an effect on triggering GC earlier, but in real apps it is almost hopeless to avoid GC, except for very carefully written programs with no dependenciesm, and if GC happens, then reducing GC mark times gives bigger bang for the buck.

  • Post Author
    ljm
    Posted March 31, 2025 at 10:56 pm

    You're not really writing 'Go' anymore when you're optimising it, it's defeating the point of the language as a simple but powerful interface over networked services.

  • Post Author
    jensneuse
    Posted March 31, 2025 at 11:06 pm

    You can often fool yourself by using sync.Pool. pprof looks great because no allocs in benchmarks but memory usage goes through the roof. It's important to measure real world benefits, if any, and not just synthetic benchmarks.

  • Post Author
    kevmo314
    Posted March 31, 2025 at 11:35 pm

    Zero-copy is totally underrated. Like the site alludes to, Go's interfaces make it reasonably accessible to write zero-copy code but it still needs some careful crafting. The payoff is great though, I've often been surprised by how much time is spent allocating and shuffling memory around.

  • Post Author
    jrockway
    Posted March 31, 2025 at 11:49 pm

    GOMEMLIMIT has saved me a number of times. In containerized production, it's nice, because sometimes jobs are ephemeral and don't even do enough allocations to hit the memory limit, so you don't spend any time in GC. But it's saved me the most times in CI where golangci-lint or govulncheck can't complete without running out of memory on a kind-of-large CI machine. Set GOMEMLIMIT and it eventually completes. (I switched to nogo, though, so at least golangci-lint isn't a problem anymore.)

  • Post Author
    nikolayasdf123
    Posted April 1, 2025 at 2:18 am

    nice article. good to see statements backed up by Benchmarks right there

  • Post Author
    nikolayasdf123
    Posted April 1, 2025 at 2:21 am

    nicely organised. I feel like this could grow into community driven current state-of-the-art of optimisation tips for Go. just need to allow people edit/comment their input easily (preferably in-place). I see there is github repo, but my bet people would not actively add their input/suggestions/research there, it is hidden too far from the content/website itself

  • Post Author
    EdwardDiego
    Posted April 1, 2025 at 2:56 am

    Huh, this surprises me about Golang, didn't realise it was so similar to C with struct alignment. https://goperf.dev/01-common-patterns/fields-alignment/#why-…

  • Post Author
    _345
    Posted April 1, 2025 at 4:10 am

    Anyone know of a resource like this but for Python 3?

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.