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

Brand New Layouts with CSS Subgrid

https://www.joshwcomeau.com/css/subgrid/
107•joshwcomeau•13h ago•26 comments

Show HN: KiDoom – Running DOOM on PCB Traces

https://www.mikeayles.com/#kidoom
136•mikeayles•7h ago•17 comments

Surprisingly, Emacs on Android is pretty good

https://kristofferbalintona.me/posts/202505291438/
70•harryday•2d ago•17 comments

Space Truckin' – The Nostromo (2012)

https://alienseries.wordpress.com/2012/10/23/space-truckin-the-nostromo/
44•exvi•3h ago•6 comments

Show HN: A WordPress plugin that rewrites image URLs for near-zero-cost delivery

https://wordpress.org/plugins/bandwidth-saver/
40•cr1st1an•3h ago•24 comments

A new bridge links the math of infinity to computer science

https://www.quantamagazine.org/a-new-bridge-links-the-strange-math-of-infinity-to-computer-scienc...
150•digital55•9h ago•46 comments

Show HN: We built an open source, zero webhooks payment processor

https://github.com/flowglad/flowglad
262•agreeahmed•11h ago•153 comments

Java Decompiler

http://java-decompiler.github.io
24•mooreds•3d ago•3 comments

Trillions spent and big software projects are still failing

https://spectrum.ieee.org/it-management-software-failures
367•pseudolus•17h ago•320 comments

CS234: Reinforcement Learning Winter 2025

https://web.stanford.edu/class/cs234/
52•jonbaer•5h ago•6 comments

FLUX.2: Frontier Visual Intelligence

https://bfl.ai/blog/flux-2
266•meetpateltech•13h ago•79 comments

The myth of reflected power (2017)

https://www.iz2uuf.net/wp/index.php/2017/07/29/the-myth-of-reflected-power/
15•pera•2h ago•4 comments

How to repurpose your old phone into a web server

https://far.computer/how-to/
196•louismerlin•3d ago•73 comments

Launch HN: Onyx (YC W24) – Open-source chat UI

177•Weves•15h ago•128 comments

Marble Springs (1993)

https://www.eastgate.com/MS/Title_184.html
16•prismatic•5d ago•0 comments

The fall of Labubus and the mush of modern internet trends

https://www.michigandaily.com/arts/digital-culture/the-fall-of-labubus-and-the-mush-of-modern-int...
69•gnabgib•2d ago•84 comments

Google Antigravity exfiltrates data via indirect prompt injection attack

https://www.promptarmor.com/resources/google-antigravity-exfiltrates-data
605•jjmaxwell4•11h ago•168 comments

The Bughouse Effect

https://tsvibt.blogspot.com/2025/11/the-bughouse-effect.html
21•surprisetalk•9h ago•4 comments

Space: 1999 – Special Effects Techniques

https://catacombs.space1999.net/main/pguide/upsfx.html
23•exvi•4h ago•4 comments

1,700-year-old Roman sarcophagus is unearthed in Budapest

https://apnews.com/article/hungary-roman-sarcophagus-discovery-budapest-77a41fe190bbcc167b43d0514...
38•gmays•1d ago•16 comments

Jakarta is now the biggest city in the world

https://www.axios.com/2025/11/24/jakarta-tokyo-worlds-biggest-city-population
287•skx001•23h ago•197 comments

Ilya Sutskever: We're moving from the age of scaling to the age of research

https://www.dwarkesh.com/p/ilya-sutskever-2
241•piotrgrabowski•12h ago•200 comments

Reinventing how .NET builds and ships (again)

https://devblogs.microsoft.com/dotnet/reinventing-how-dotnet-builds-and-ships-again/
136•IcyWindows•6h ago•52 comments

Unifying our mobile and desktop domains

https://techblog.wikimedia.org/2025/11/21/unifying-mobile-and-desktop-domains/
122•todsacerdoti•12h ago•34 comments

Someone at YouTube Needs Glasses: The Prophecy Has Been Fulfilled

https://jayd.ml/2025/11/10/someone-at-youtube-needs-glasses-prophecy-fulfilled.html
449•jaydenmilne•7h ago•332 comments

BebboSSH: SSH2 implementation for Amiga systems (68000, GPLv3)

https://franke.ms/git/bebbo/bebbossh
14•snvzz•3h ago•2 comments

Notes on the Troubleshooting and Repair of Computer and Video Monitors

https://www.repairfaq.org/sam/monfaq.htm
30•WorldPeas•6h ago•8 comments

Python is not a great language for data science

https://blog.genesmindsmachines.com/p/python-is-not-a-great-language-for
172•speckx•12h ago•174 comments

Constant-time support coming to LLVM: Protecting cryptographic code

https://blog.trailofbits.com/2025/11/25/constant-time-support-coming-to-llvm-protecting-cryptogra...
57•ahlCVA•16h ago•21 comments

What they don't tell you about maintaining an open source project

https://andrej.sh/blog/maintaining-open-source-project/
124•andrejsshell•7h ago•91 comments