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

Unusual circuits in the Intel 386's standard cell logic

https://www.righto.com/2025/11/unusual-386-standard-cell-circuits.html
101•Stratoscope•6h ago•14 comments

A monopoly ISP refuses to fix upstream infrastructure

https://sacbear.com/xfinity-wont-fix-internet/
246•vedmed•8h ago•105 comments

GCC SC approves inclusion of Algol 68 Front End

https://gcc.gnu.org/pipermail/gcc/2025-November/247020.html
116•edelsohn•7h ago•36 comments

The privacy nightmare of browser fingerprinting

https://kevinboone.me/fingerprinting.html
551•ingve•16h ago•331 comments

We Induced Smells With Ultrasound

https://writetobrain.com/olfactory
460•exr0n•1d ago•122 comments

WorldGen – Text to Immersive 3D Worlds

https://www.meta.com/en-gb/blog/worldgen-3d-world-generation-reality-labs-generative-ai-research/
200•smusamashah•12h ago•65 comments

Ubuntu LTS releases to 15 years with Legacy add-on

https://canonical.com/blog/canonical-expands-total-coverage-for-ubuntu-lts-releases-to-15-years-w...
95•taubek•2d ago•37 comments

NTSB report: Decryption of images from the Titan submersible camera [pdf] (2024)

https://data.ntsb.gov/Docket/Document/docBLOB?ID=18741602&FileExtension=pdf&FileName=Underwater%2...
110•bmurray7jhu•9h ago•51 comments

Show HN: Forty.News – Daily news, but on a 40-year delay

https://forty.news
271•foxbarrington•14h ago•112 comments

Meta buried 'causal' evidence of social media harm, US court filings allege

https://www.reuters.com/sustainability/boards-policy-regulation/meta-buried-causal-evidence-socia...
298•pseudolus•8h ago•111 comments

An Economy of AI Agents

https://arxiv.org/abs/2509.01063
65•nerder92•7h ago•39 comments

The Boring Part of Bell Labs

https://elizabethvannostrand.substack.com/p/the-boring-part-of-bell-labs
97•AcesoUnderGlass•3d ago•15 comments

The 1957 “Spaghetti-Grows-on-Trees” Hoax

https://www.openculture.com/2025/11/the-1957-spaghetti-grows-on-trees-hoax.html
24•PaulHoule•1w ago•10 comments

$1900 Bug Bounty to Fix the Lenovo Legion Pro 7 16IAX10H's Speakers on Linux

https://github.com/nadimkobeissi/16iax10h-linux-sound-saga
249•rany_•1w ago•111 comments

`satisfies` is my favorite TypeScript keyword (2024)

https://sjer.red/blog/2024-12-21/
162•surprisetalk•4d ago•133 comments

Google Revisits JPEG XL in Chromium After Earlier Removal

https://windowsreport.com/google-revisits-jpeg-xl-in-chromium-after-earlier-removal/
60•eln1•3h ago•11 comments

CERN Council reviews feasibility study for a next-generation collider

https://home.cern/news/press-release/accelerators/cern-council-reviews-feasibility-study-next-gen...
16•elashri•1w ago•5 comments

Garibaldi, History's Sexiest Revolutionary?

https://www.historyextra.com/period/victorian/historys-sexiest-revolutionary-meet-the-mesmerising...
31•thomassmith65•1w ago•20 comments

Simplifying Cluster-Wide PostgreSQL Execution with Exec_node() and Spock OSS

https://www.pgedge.com/blog/simplifying-cluster-wide-sql-execution-in-pgedge-with-exec_node
4•pgedge_postgres•6d ago•0 comments

Pixel Art Tips for Programmers

https://jslegenddev.substack.com/p/5-pixel-art-tips-for-programmers-3d6
96•ibobev•1d ago•21 comments

Show HN: Build the habit of writing meaningful commit messages

https://github.com/arpxspace/smartcommit
67•Aplikethewatch•12h ago•79 comments

Windows ARM64 Internals: Deconstructing Pointer Authentication

https://www.preludesecurity.com/blog/windows-arm64-internals-deconstructing-pointer-authentication
59•todsacerdoti•11h ago•2 comments

China reaches energy milestone by "breeding" uranium from thorium

https://www.scmp.com/news/china/science/article/3331312/china-reaches-energy-independence-milesto...
281•surprisetalk•15h ago•214 comments

MCP Apps just dropped (OpenAI and Anthropic collab) and I think this is huge

http://blog.modelcontextprotocol.io/posts/2025-11-21-mcp-apps/
17•mercury24aug•6h ago•6 comments

Show HN: A tool to safely migrate GitHub Actions workflows to Ubuntu-slim runner

https://github.com/fchimpan/gh-slimify
46•r4mimu•1w ago•0 comments

Markdown is holding you back

https://newsletter.bphogan.com/archive/issue-45-markdown-is-holding-you-back/
107•zdw•13h ago•76 comments

The realities of being a pop star

https://itscharlibb.substack.com/p/the-realities-of-being-a-pop-star
215•lovestory•15h ago•117 comments

Agent design is still hard

https://lucumr.pocoo.org/2025/11/21/agents-are-hard/
380•the_mitsuhiko•22h ago•218 comments

Tektronix equipment has been used in many movies and shows

https://vintagetek.org/tektronix-in-movies-shows/
99•stmw•6d ago•26 comments

A Reverse Engineer's Anatomy of the macOS Boot Chain and Security Architecture

https://stack.int.mov/a-reverse-engineers-anatomy-of-the-macos-boot-chain-security-architecture/
104•19h•12h ago•34 comments