frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

4-10x faster in-process pub/sub for Go

https://github.com/kelindar/event
75•kelindar•5h ago

Comments

kelindar•5h ago
This might be useful to some if you need a very light pub/sub inside one process.

I was building a small multiplayer game in Go. Started with a channel fan-out but (for no particular reason) wanted to see if we can do better. Put together this tiny event bus to test, and on my i7-13700K it delivers events in 10-40ns, roughly 4-10x faster than the plain channel loop, depending on the configuration.

zx2c4•3h ago
> about 4x to 10x faster than channels.

I'd be interested to learn why/how and what the underlying structural differences are that make this possible.

MathMonkeyMan•3h ago
I didn't look, but I don't think of channels as a pub/sub mechanism. You can have a producer close() a channel to notify consumers of a value available somewhere else, or you can loop through a bunch of buffered channels and do nonblocking sends.

A different design, without channels, could improve on those.

atombender•1h ago
I prefer to think of channels as a memory-sharing mechanism.

In most cases where you want to send data between concurrent goroutines, channels are a better primitive, as they allow the sender and receiver to safely and concurrently process data without needing explicit locks. (Internally, channels are protected with mutexes, but that's a single, battle-tested and likely bug-free implementation shared by all users of channels.)

The fact that channels also block on send/receive means and support buffering means that there's a lot more to them, but that's how you should think of them. The fact that channels look like a queue if you squint is a red herring that has caused many a junior developer to abuse them for that purpose, but they are a surprisingly poor fit for that. Even backpressure tends to be something you want to control manually (using intermediate buffers and so on), because channels can be fiendishly hard to debug once you chain more than a couple of them. Something forgets to close a close a channel, and your whole pipeline can stall. Channels are also slow, requiring mutex locking even in scenarios where data isn't in need of locking and could just be passed directly between functions.

Lots of libraries (such as Rill and go-stream) have sprung up that wrap channels to model data pipelines (especially with generics it's become easier to build generic operators like deduping, fan-out, buffering and so on), but I've found them to be a bad idea. Channels should remain a low-level primitive to build pipelines, but they're not what you should use as your main API surface.

MathMonkeyMan•1h ago
> Channels should remain a low-level primitive to build pipelines, but they're not what you should use as your main API surface.

I remember hearing (not sure where) that this is a lesson that was learned early on in Go. Channels were the new hotness, so let's use them to do things that were not possible before. But it turned out that Go was better for doing what was already possible before, but more cleanly.

absolute_unit22•2h ago
> High Performance: Processes millions of events per second, about 4x to 10x faster than channels.

Wow - that’s a pretty impressive accomplishment. I’ve been meaning to move some workers I have to a pub/sub on https://www.typequicker.com.

I might try using this in prod. I don’t really need the insane performance benefits as I don’t have my traffic lol - but I always like experimenting with new open source libraries - especially while the site isn’t very large yet

hinkley•2h ago
It’s always worth discussing what features were thrown out to get the performance boost, whether it’s fair for those features to impose a tax on all users who don’t or rarely use those features, and whether there’s a way to rearrange the code so that the lesser used features are a low cost abstraction, one that you mostly only pay if you use those features and are cheap if not free if you don’t.

There’s a lot of spinoff libraries out there that have provoked a reaction from the core team that cuts down cost of their implementation by 25, 50%. And that’s a rising tide that lifts all boats.

tombert•2h ago
Interesting, I need to dig into the guts of this because this seems cool.

I'm a bit out of practice with Go but I never thought that the channels were "slow", so getting 4-10x the speed is pretty impressive. I wonder if it shares any design with LMAX Disruptor...

bob1029•37m ago
> I wonder if it shares any design with LMAX Disruptor...

I've recently switched from using Disruptor.NET to Channel<T> in many of my .NET implementations that require inter-thread sync primitives. Disruptor can be faster, but I really like the semantics of the built-in types.

https://learn.microsoft.com/en-us/dotnet/core/extensions/cha...

https://learn.microsoft.com/en-us/dotnet/api/system.threadin...

minaguib•1h ago
OP: the readme could really benefit from a section describing the underlying methodology, and comparing it to other approaches (Go channels, LMAX, etc...)
karel-3d•20m ago
The actual code and the actual bench is very short.
singron•14m ago
After a brief skim, it looks like this implementation is highly optimized for throughput and broadcasts whereas a channel has many other usecases.

Consumers subscribing to the same event type are placed in a group. There is a single lock for the whole group. When publishing, the lock is taken once and the event is replicated to each consumer's queue. Consumers take the lock and swap their entire queue buffer, which lets them consume up to 128 events per lock/unlock.

Since channels each have a lock and only take 1 element at a time, they would require a lot more locking and unlocking.

There is also some frequent polling to maintain group metadata, so this could be less ideal in low volume workloads where you want CPU to go to 0%.

Ford CEO says Waymo's approach to autonomous driving makes more sense

https://fortune.com/2025/06/27/ford-ceo-jim-farley-waymo-self-driving-lidar-more-sense-than-tesla-aspen-ideas/
1•01-_-•56s ago•0 comments

Anticheat Update Tracking

https://not-matthias.github.io/posts/anticheat-update-tracking/
1•not-matthias•2m ago•0 comments

OpenAI Leadership Responds to Meta Offers: 'Someone Has Broken into Our Home'

https://www.wired.com/story/openai-meta-leadership-talent-rivalry/
1•mfiguiere•3m ago•0 comments

Context Engineering

https://simonwillison.net/2025/Jun/27/context-engineering/
2•handfuloflight•7m ago•0 comments

Datastar – The Hypermedia Framework

https://data-star.dev/
1•thunderbong•9m ago•0 comments

"I've learned a lot from [name] " scams on YouTube

https://misbehavingbots.com/ive-learned-a-lot-from-name-scams-on-youtube
1•sevazhidkov•14m ago•0 comments

Dev Log – The New Multithreading Framework – Steam News

https://store.steampowered.com/news/app/1366540/view/543361383085900510
1•thunderbong•14m ago•0 comments

Using AI to Play Quarterback in VR with a Real Ball

https://mluogh.com/posts/vr-football/
1•hahaxdxd123•15m ago•0 comments

Show HN: I Made Cursor for Prompts Extension

https://promptdc.com/
1•pvisilias•17m ago•0 comments

Ask HN: Does Gemini create an empty project in Google Cloud?

1•marcosscriven•18m ago•0 comments

ZeroRISC Gets $10M Funding, Says Open-Source Silicon Security Inevitable

https://www.eetimes.com/zerorisc-gets-10-million-funding-says-open-source-silicon-security-inevitable/
2•wslh•21m ago•0 comments

NHS to save money by shifting from treatment to prevention

https://www.theguardian.com/society/2025/jun/29/nhs-health-policy-labour-ten-year-plan-change
1•8bitsrule•25m ago•0 comments

Ask HN: What do use for private service monitoring?

1•vednig•27m ago•1 comments

Asynchronous Error Handling Is Hard

https://parallelprogrammer.substack.com/p/asynchronous-error-handling-is-hard
2•hedgehog•34m ago•0 comments

Using DuckDB WASM and Cloudflare R2 to host and query big data (for almost free)

https://andrewpwheeler.com/2025/06/29/using-duckdb-wasm-cloudflare-r2-to-host-and-query-big-data-for-almost-free/
2•apwheele•34m ago•0 comments

I built isfujivisible.com: live Mt Fuji visibility tracker

https://isfujivisible.com
1•orkhanfarmanli•37m ago•1 comments

Making JavaScript Simple Again

https://www.rugu.dev/en/blog/making-js-simple/
1•kugurerdem•38m ago•0 comments

Inline-C: Write inline C in Haskell

https://github.com/fpco/inline-c/tree/master/inline-c
2•burnt-resistor•40m ago•0 comments

Error handling in Rust

https://felix-knorr.net/posts/2025-06-29-rust-error-handling.html
19•emschwartz•41m ago•6 comments

Show HN: Escape Rope – an open-source, self-hosted Tinder clone for jobs

1•chaosharmonic•46m ago•0 comments

Can you pass my questions to your technical person? I don't think you understand

https://mastodon.neilzone.co.uk/@neil/114768125625705037
2•ColinWright•47m ago•1 comments

Ask HN: What Are You Working On? (June 2025)

3•david927•48m ago•7 comments

The three rules of conference panels

https://www.economist.com/business/2025/06/23/the-three-rules-of-conference-panels
2•austinallegro•49m ago•1 comments

Counting Down Capabilities to AGI

https://shash42.substack.com/p/counting-down-capabilities-to-agi
1•shash42•50m ago•1 comments

Earth is trapping much more heat than climate models forecast

https://theconversation.com/earth-is-trapping-much-more-heat-than-climate-models-forecast-and-the-rate-has-doubled-in-20-years-258822
5•GeoAtreides•52m ago•0 comments

AI-SDK-cpp: Modern C++ AI SDK

https://github.com/ClickHouse/ai-sdk-cpp
2•samaysharma•53m ago•0 comments

Stanford cuts $140M, warns of layoffs as research funding dries up

https://www.sfchronicle.com/bayarea/article/stanford-budget-cuts-layoffs-research-funding-20399637.php
6•breadwinner•53m ago•1 comments

Show HN: Profile GPU Kernels with One Command, Zero GPU Setup

https://github.com/Herdora/chisel
1•technoabsurdist•54m ago•0 comments

Show HN: ColecoVision Emulator in Zig

https://github.com/braheezy/zoleco
3•braheezy•58m ago•1 comments

YouTube No Translation

https://addons.mozilla.org/en-GB/firefox/addon/youtube-no-translation/
1•doener•58m ago•1 comments