frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Optimizing Heap Allocations in Go: A Case Study

https://www.dolthub.com/blog/2025-04-18-optimizing-heap-allocations/
54•ingve•7mo ago

Comments

returningfory2•7mo ago
> It's possible that this is a compiler bug. It's also possible that there's some fringe case where the reference actually can escape via that method call, and the compiler doesn't have enough context to rule it out.

Here's an example, I think: suppose the method spawns a new goroutine that contains a reference to `chunkStore`. This goroutine can outlive the `ReadBytes` function call, and thus Go has to heap allocate the thing being referenced.

In general, this kind of example makes me suspect that Go's escape analysis algorithm treats any method call as a black box and heap allocates anything being passed to it by reference.

athorax•7mo ago

  The notion of stack vs heap allocation isn't something that even exists in the language. Users are expected to not worry about it... until, of course, until you're optimizing performance and you need to worry about it.
This is one of the best and worst aspects with Go. Anyone can write pretty performant code without having to understand the underlying memory model. If you get to the point where you are trying to optimize at this level, the benefits of using a more approachable language start to fall apart and you spend more time chasing implementation details.
nu11ptr•7mo ago
In general, it is a win, since it lets you code faster and 80-90% the performance doesn't matter. Over time, you learn generally what leads to heap allocs and what doesn't. In rare hot spot, using -m will show you the allocations and you can optimize.
athorax•7mo ago
I would generally agree. It's good enough performance for most applications. For those that it isn't fast enough for (even with optimizations like these), it still allows for rapid prototyping to arrive at that conclusion.
Ygg2•7mo ago
I think same applies to any GC language. Ride is fun until GC starts either taking too much time, too much memory or taking too much of CPU.
Thaxll•7mo ago
At least you have the tools to understand where things get allocated.
38•7mo ago
instead of this:

    t.Buf = []byte{}
you can just do:

    t.Buf = nil
rsc•7mo ago
Those are semantically different (one is nil and one is not) but neither allocates.
virexene•7mo ago
I wonder if the reason the escape analysis fails could be that, for small enough types, the concrete value is directly inlined inside the interface value, instead of the latter being "a smart pointer" as the author said. So when the compiler needs to take a reference to the concrete value in `vs.chunkStore`, that ends up as an internal pointer inside the `vs` allocation, requiring it to be on the heap.

Either that or the escape analysis just isn't smart enough; taking a pointer to an internal component of an interface value seems like a bit of a stretch.

Snawoot•7mo ago
I had an attempt to improve performance of memory allocation with the use of arenas in Go and I chose freelist datastructure[1]

It almost doesn't use unsafe except one line to cast pointer types. I measured practical performance boost with "container/list" implementation hooked to my allocator. All in all it performs 2-5 times faster or up to 10 times faster if we can get rid[2] of any and allocations implied by the use of it.

All in all, heap allocations can be not that bad at all if you approach them from another angle.

[1]: https://github.com/Snawoot/freelist

[2]: https://github.com/Snawoot/list

Learning Music with Strudel

https://terryds.notion.site/Learning-Music-with-Strudel-2ac98431b24180deb890cc7de667ea92
134•terryds•6d ago•28 comments

Mistral 3 family of models released

https://mistral.ai/news/mistral-3
254•pember•1h ago•69 comments

Nixtml: Static website and blog generator written in Nix

https://github.com/arnarg/nixtml
37•todsacerdoti•1h ago•6 comments

Addressing the adding situation

https://xania.org/202512/02-adding-integers
193•messe•5h ago•57 comments

Peter Thiel's Apocalyptic Worldview Is a Dangerous Fantasy

https://jacobin.com/2025/11/peter-thiel-palantir-apocalypse-antichrist
46•robtherobber•21m ago•1 comments

Show HN: Marmot – Single-binary data catalog (no Kafka, no Elasticsearch)

https://github.com/marmotdata/marmot
41•charlie-haley•1h ago•6 comments

Advent of Compiler Optimisations 2025

https://xania.org/202511/advent-of-compiler-optimisation
240•vismit2000•6h ago•33 comments

A series of vignettes from my childhood and early career

https://www.jasonscheirer.com/weblog/vignettes/
86•absqueued•4h ago•50 comments

Python Data Science Handbook

https://jakevdp.github.io/PythonDataScienceHandbook/
80•cl3misch•4h ago•15 comments

YesNotice

https://infinitedigits.co/docs/software/yesnotice/
39•surprisetalk•1w ago•21 comments

Apple Releases Open Weights Video Model

https://starflow-v.github.io
338•vessenes•11h ago•106 comments

What will enter the public domain in 2026?

https://publicdomainreview.org/features/entering-the-public-domain/2026/
391•herbertl•13h ago•249 comments

YouTube increases FreeBASIC performance (2019)

https://freebasic.net/forum/viewtopic.php?t=27927
119•giancarlostoro•2d ago•23 comments

Comparing AWS Lambda ARM64 vs. x86_64 Performance Across Runtimes in Late 2025

https://chrisebert.net/comparing-aws-lambda-arm64-vs-x86_64-performance-across-multiple-runtimes-...
89•hasanhaja•7h ago•39 comments

Proximity to coworkers increases long-run development, lowers short-term output (2023)

https://pallais.scholars.harvard.edu/publications/power-proximity-coworkers-training-tomorrow-or-...
105•delichon•2h ago•68 comments

DeepSeek-v3.2: Pushing the frontier of open large language models [pdf]

https://huggingface.co/deepseek-ai/DeepSeek-V3.2/resolve/main/assets/paper.pdf
905•pretext•1d ago•430 comments

India orders smartphone makers to preload state-owned cyber safety app

https://www.reuters.com/sustainability/boards-policy-regulation/india-orders-mobile-phones-preloa...
827•jmsflknr•1d ago•605 comments

Fallout 2's Chris Avellone describes his game design philosophy

https://arstechnica.com/gaming/2025/12/fallout-2-designer-chris-avellone-recalls-his-first-forays...
19•LaSombra•47m ago•2 comments

I Designed and Printed a Custom Nose Guard to Help My Dog with DLE

https://snoutcover.com/billie-story
6•ragswag•2d ago•1 comments

Beej's Guide to Learning Computer Science

https://beej.us/guide/bglcs/
262•amruthreddi•2d ago•94 comments

Zig's new plan for asynchronous programs

https://lwn.net/SubscriberLink/1046084/4c048ee008e1c70e/
66•messe•2h ago•51 comments

An LED panel that shows the aviation around you

https://github.com/AxisNimble/TheFlightWall_OSS
54•yzydserd•5d ago•10 comments

How Brian Eno Created Ambient 1: Music for Airports (2019)

https://reverbmachine.com/blog/deconstructing-brian-eno-music-for-airports/
136•dijksterhuis•8h ago•71 comments

Show HN: RunMat – runtime with auto CPU/GPU routing for dense math

https://github.com/runmat-org/runmat
9•nallana•1h ago•1 comments

Lazier Binary Decision Diagrams for set-theoretic types

https://elixir-lang.org/blog/2025/12/02/lazier-bdds-for-set-theoretic-types/
21•tvda•4h ago•2 comments

Rootless Pings in Rust

https://bou.ke/blog/rust-ping/
95•bouk•9h ago•68 comments

Tom Stoppard has died

https://www.bbc.com/news/articles/c74xe49q7vlo
147•mstep•2d ago•45 comments

Reverse math shows why hard problems are hard

https://www.quantamagazine.org/reverse-mathematics-illuminates-why-hard-problems-are-hard-20251201/
146•gsf_emergency_6•14h ago•29 comments

After Windows Update, Password icon invisible, click where it used to be

https://support.microsoft.com/en-us/topic/august-29-2025-kb5064081-os-build-26100-5074-preview-3f...
141•zdw•14h ago•143 comments

Man unexpectedly cured of HIV after stem cell transplant

https://www.newscientist.com/article/2506595-man-unexpectedly-cured-of-hiv-after-stem-cell-transp...
128•doener•6h ago•25 comments