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

System 7 natively boots on the Mac mini G4

https://macos9lives.com/smforum/index.php?topic=7711.0
117•ibobev•3h ago•18 comments

WinApps: Run Windows apps as if they were a part of the native Linux OS

https://github.com/winapps-org/winapps
59•klaussilveira•3d ago•10 comments

Airbus A320 – intense solar radiation may corrupt data critical for flight

https://www.airbus.com/en/newsroom/press-releases/2025-11-airbus-update-on-a320-family-precaution...
237•pyrophoenix•9h ago•46 comments

Imgur geo-blocked the UK, so I geo-unblocked my network

https://blog.tymscar.com/posts/imgurukproxy/
346•tymscar•13h ago•114 comments

Every mathematician has only a few tricks (2020)

https://mathoverflow.net/questions/363119/every-mathematician-has-only-a-few-tricks
62•nill0•5h ago•11 comments

A triangle whose interior angles sum to zero

https://www.johndcook.com/blog/2025/11/28/tricusp-triangle/
83•tzury•6h ago•41 comments

Molly: An Improved Signal App

https://molly.im/
299•dtj1123•13h ago•165 comments

Confessions of a Software Developer: No More Self-Censorship

https://kerrick.blog/articles/2025/confessions-of-a-software-developer-no-more-self-censorship/
168•Kerrick•8h ago•160 comments

So you wanna build a local RAG?

https://blog.yakkomajuri.com/blog/local-rag
259•pedriquepacheco•14h ago•54 comments

The weirdest tool I own is also one of the most useful

https://www.zdnet.com/article/the-weirdest-tool-i-own-is-also-one-of-the-most-useful-and-its-14-o...
16•fcpguru•2d ago•0 comments

Airloom – 3D Flight Tracker

https://objectiveunclear.com/airloom.html
203•azinman2•14h ago•66 comments

Show HN: Mu – The Micro Network

https://github.com/asim/mu
18•asim•4d ago•8 comments

The original ABC language, Python's predecessor (1991)

https://github.com/gvanrossum/abc-unix
96•tony•11h ago•25 comments

A first look at Django's new background tasks

https://roam.be/notes/2025/a-first-look-at-djangos-new-background-tasks/
95•roam•9h ago•19 comments

28M Hacker News comments as vector embedding search dataset

https://clickhouse.com/docs/getting-started/example-datasets/hackernews-vector-search-dataset
370•walterbell•13h ago•145 comments

Fabric Project

https://github.com/Fabric-Project/Fabric
46•brcmthrowaway•8h ago•7 comments

Neato vacuum robots to stop working

https://support.neatorobotics.com/support/solutions/articles/204000073686-announcement-6th-oct-2025
28•simonlondon•3h ago•13 comments

How good engineers write bad code at big companies

https://www.seangoedecke.com/bad-code-at-big-companies/
296•gfysfm•11h ago•199 comments

I mathematically proved the best "Guess Who?" strategy [video]

https://www.youtube.com/watch?v=_3RNB8eOSx0
60•surprisetalk•6d ago•15 comments

The 'S&P 493' reveals a different U.S. economy

https://www.msn.com/en-us/money/markets/the-s-p-493-reveals-a-very-different-us-economy/ar-AA1R1VUJ
30•MilnerRoute•1h ago•3 comments

Language is primarily a tool for communication rather than thought (2024) [pdf]

https://gwern.net/doc/psychology/linguistics/2024-fedorenko.pdf
36•netfortius•16h ago•7 comments

How to get Pandoc to respect custom table styles in Word templates

https://johnathandos.com/posts/2025-11-24-custom-tables-with-pandoc/
11•johnathandos•4d ago•1 comments

The Great Downzoning

https://worksinprogress.co/issue/the-great-downzoning/
3•barry-cotter•2h ago•0 comments

Flight disruption warning as Airbus requests modifications to 6k planes

https://www.bbc.com/news/live/cvg4y6g74ert
197•nrhrjrjrjtntbt•10h ago•85 comments

True P2P Email on Top of Yggdrasil Network

https://github.com/JB-SelfCompany/Tyr
133•basemi•14h ago•23 comments

Don't tug on that, you never know what it might be attached to (2016)

https://blog.plover.com/2016/07/01/#tmpdir
118•todsacerdoti•15h ago•53 comments

Show HN: Choose your own adventure style Presentation

https://github.com/Skarlso/adventure-voter
19•skarlso•1w ago•4 comments

Electron vs. Tauri

https://www.dolthub.com/blog/2025-11-13-electron-vs-tauri/
52•birdculture•11h ago•24 comments

Effective harnesses for long-running agents

https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
96•diwank•12h ago•32 comments

Can Dutch universities do without Microsoft?

https://dub.uu.nl/en/news/can-dutch-universities-do-without-microsoft
281•robtherobber•15h ago•283 comments