frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

How fast is Go? Simulating particles on a smart TV

https://dgerrells.com/blog/how-fast-is-go-simulating-millions-of-particles-on-a-smart-tv
110•lossolo•4mo ago

Comments

truth_seeker•4mo ago
> On the topic of memory, with millions of particles the server barely breaks over 100mb

Although experimental as of now, but use of arena package is a natual fit here.

sa46•4mo ago
The arena experiment is on indefinite hold:

> Note, 2023-01-17. This proposal is on hold indefinitely due to serious API concerns.

https://github.com/golang/go/issues/51317

Potential successor: https://github.com/golang/go/discussions/70257

truth_seeker•4mo ago
>Note that the best-case scenario is the elimination of the overheads above to 0, which is at most ~10% in these particular benchmarks. Thus, it's helpful to consider the proportion of GC overhead eliminated relative to that 10% (so, 7% reduction means 70% GC overhead reduction).

Wow. amazing to see of off-heap allocation can be that good

https://go.googlesource.com/proposal/+/refs/heads/master/des...

pjmlp•4mo ago
Meanwhile Java and .NET have had off-heap and arenas for a while now.

Which goes to show how Go could be much better, if being designed with the learnings of others taken into account.

The adoption of runtime.KeepAlive() [0], and the related runtime.AddCleanup() as replacement for finalizers are also learnings from other languages [1].

[0] - https://learn.microsoft.com/en-us/dotnet/api/system.gc.keepa...

[1] - https://openjdk.org/jeps/421

truth_seeker•4mo ago
What a coincedence ! :)

Recently used MemorySegment in Java, it is extremely good. Just yesterday i implemented Map and List interface using MemorySegment as backing store for batch operations instead of using OpenHFT stuff.

Tried -XX:TLABSize before but wasnt getting the deserved performance.

Not sure about .NET though, havent used since last decade.

pixelpoet•4mo ago
Gaffer (Glenn Fiedler, mentioned in the article) would also say, and I quote, "if you use Euler, then you're a bloody idiot" :) This simulation is using Euler integration.
shoo•4mo ago
https://gafferongames.com/post/integration_basics/
rustystump•4mo ago
I suppose I am a bloody idiot.

This uses a simple delta time to smooth updates across frames rather than attempting something more formal. Based on the sister comment I think this is actually Semi-implicit Euler which still makes me an idiot.

Eg, velocity += acceleration * dt; position += velocity * dt;

Although, I add friction in a bad spot so maybe that is what you mean.

shoo•4mo ago
If you're doing semi-implicit Euler that's pretty good, per gaffer's article, semi-implicit Euler has the advantage of being symplectic, i.e. its an integration method that conserves the total energy of the system you are simulating (energy conservation! physicists love it!).

the particle motion in your videos looks reasonably natural, there's no obvious signs of particles seemingly gaining energy from nothing (apart from when they are perturbed by the mouse cursor), so as the resulting motion looks natural, what you are doing is fine and there's no actual problem you need to solve.

if instead of simulating independent particles you were trying to accurately simulate cloth or a deformable rigid body e.g. a metallic object crashing into something, where each node in your cloth / rigid body was a particle tethered to its neighbours, that might be a whole different can of worms and justify looking into RK4 or implicit Euler where you need to solve a big linear system of equations each timestep. but you're not doing that, so no need to overcomplicate things!

pixelpoet•4mo ago
Let's bear in mind that Australians call their best friends Good Cunts, and try to take it the best possible way :D I don't even disagree with him, it's just too easy to do better.

The friction/damping term you've added is absolutely necessary to counteract the systematic energy gain from Euler integration, and with better integration, you need less / no unphysical damping, leading to more of that delicious chaotic behaviour we're all looking for.

You can even cheese this with infinite amount of computation if you wanted to do it braindead style (which is still super instructive!), by just repeating the step function with a scaled-down dt until the position components agree to within some tolerance.

The rest is an incredibly deep rabbithole, which I've been enjoying since decades :D

mosura•4mo ago
Is this on a smart TV or a server feeding the results to a smart TV? Seems like quite an important difference.
jypepin•4mo ago
you should probably read the article then, it's pretty clearly explained
mosura•4mo ago
I did and don’t understand why the title is “simulating particles on a smart TV” if that is not what it is doing.
rob74•4mo ago
Ok, maybe that was a little bit clickbaity, but the first sentence should clarify it:

> The challenge, simulate millions of particles in golang, multi-player enabled, cpu only, smart tv compatible.

Usually you wouldn't do that on the server, but if you want performance metrics, it's probably easier to measure on the server than on X clients?

dev-ns8•4mo ago
"No client simulation allowed only server."

Seriously

cogman10•4mo ago
My suggestion to the OP talking about compression.

First up, consider just PNG compressing the image for simplicity. It's a mostly black image with color dots. That would generally compress really well with PNG.

But also, knowing the nature of the image, you could pretty easily compress the image by doing offsets to the next pixel. The format could look roughly something like this

[offset byte, color byte, offset byte, color byte].

It will fail in cases where each pixel has a color and will excel when there is a run of black pixels (which there will be a lot of those). It's a dead simple format to implement and read as well.

You can even keep the frame around for writing. You'd just be counting black pixels left to right top to bottom, emitting that number or 255 then 0 resetting and then counting some more.

gus_massa•4mo ago
It also looks like half of the screen doen't change (the part that is far away fro the cursor), so compressing the xor of the new and old image would improve compression a lot.
cogman10•4mo ago
Yeah, that would also help with when the image is static with no interactions.
runjake•4mo ago
This is what I come to Hacker News for. Thank you!
rustystump•4mo ago
Author here. Surprised to see this show up.

I did try a large variety of encodings and the best was delta encoding frames followed by RLE encoding similar to what you describe. It did pretty well. However, when things start to move, it only shaved ~10-20% off the size at a significant complexity and compute cost. This was before I allowed each client to have its own frame and it was more common for there to be significant areas of black.

cogman10•4mo ago
> and compute cost

It'd definitely be tricky to get the computational performance that you'd want out of it. I'd imagine it'd be pretty easy to accidentally bust caches.

To solve for that, you could double your frame size and store the prev/next in an alternating fashion. IE [n, p, n, p, n, p] That way when you xor you are always working with highly local memory sets. You'd want to keep the frame basically global to avoid allocating.

If you wanted to be super clever then you could probably SIMD this up doing something like [n, n, n, n, p, p, p, p]. I'm not sure how you'd turn that into RLE in SIMD. I'm not clever enough for that :D (but I'm sure someone has done it).

But as you said, complexity would definitely increase rather than decrease even though you could get much better compute time.

cwmoore•4mo ago
What a beautiful beast: https://howfastisgo.dev/
nasretdinov•4mo ago
In regards to number crunching Go indeed made little effort to optimise this use case (especially since many good alternatives already existed at the time). Having said, I'm really hopeful that the SIMD proposals do eventually make it into the language, e.g. this one: https://github.com/golang/go/issues/73787#issuecomment-32081...
lenkite•4mo ago
Yes, this is the reason why there are no currently-maintained data-science/dataframe libraries in Go either
OoooooooO•4mo ago
Every DataFrame library with a significant user base uses function chaining because that's the best workflow for such stuff. Also notebook support / magic cell comments for iterative EDA.

Python: polars-py, pandas, pySpark JVM: Spark R: R

Go can't compete with this even with SIMD support.

pjmlp•4mo ago
Hopefully, as that is another area where other managed languages have finally started to taking seriously.

Julia, .NET, Java (even if preview), Swift.

While writing Assembly isn't that bad, having to deal with the Go Plan 9 Assembler syntax isn't something I am keen on putting up with.

alex-moon•4mo ago
I realise this isn't the most thoughtful comment but I hope the intended spirit comes across when I say, sincerely: ha ha yay (clapping hands)
liampulles•4mo ago
I guess the key questions are: what are the tradeoffs Go makes, and what kind of work is it well suited for?

I think Go's key strengths are syntax simplicity, niceties for large scale codebase (good monorepo support, quick builds, quick startup, easy CLIs, testing and language server built in), and good concurrency constructs.

There are controversial aspects too, like an aversion to annotations and exceptions and anything that hides a plain control flow - as well as a reluctance to evolve the syntax and basic aspects of the language. I like those things personally but that is because I find myself well aligned to Go's philosophy.

I would say that the worst parts of the language would actually be performance, I would not use Go if single threaded performance is critical (and the author Notes this). The GC is not the most efficient either. But I think given that hardware evolution is leaning towards more cores, and scaling up is leaning more towards scaling up containers, Go's choices put it in good stead here.

Go is my favourite language at the moment, has been for a while.

syngrog66•4mo ago
Nailed it.

Every tool/language designer makes trade-off choices. I like the ones Golang makes. To me it reeked of experienced folks being in charge. I have grey hairs from all the Bad Things I've had to overcome in software engineering over the decades, in production, with big money at stake, oh and late at night on weekends as a bonus. As I learned about Golang I could tell its designer(s) had too and were trying to address it.

Is it perfect in all ways? Perhaps not. But nothing ever is, so that's a non-interesting criticism in my mind. I know a Good Thing when I see it. One of the few bright spots to getting older.

Interview with 'Just use a VPS' bro (OpenClaw version) [video]

https://www.youtube.com/watch?v=40SnEd1RWUU
1•dangtony98•1m ago•0 comments

EchoJEPA: Latent Predictive Foundation Model for Echocardiography

https://github.com/bowang-lab/EchoJEPA
1•euvin•9m ago•0 comments

Disablling Go Telemetry

https://go.dev/doc/telemetry
1•1vuio0pswjnm7•11m ago•0 comments

Effective Nihilism

https://www.effectivenihilism.org/
1•abetusk•14m ago•1 comments

The UK government didn't want you to see this report on ecosystem collapse

https://www.theguardian.com/commentisfree/2026/jan/27/uk-government-report-ecosystem-collapse-foi...
2•pabs3•16m ago•0 comments

No 10 blocks report on impact of rainforest collapse on food prices

https://www.thetimes.com/uk/environment/article/no-10-blocks-report-on-impact-of-rainforest-colla...
1•pabs3•16m ago•0 comments

Seedance 2.0 Is Coming

https://seedance-2.app/
1•Jenny249•18m ago•0 comments

Show HN: Fitspire – a simple 5-minute workout app for busy people (iOS)

https://apps.apple.com/us/app/fitspire-5-minute-workout/id6758784938
1•devavinoth12•18m ago•0 comments

Dexterous robotic hands: 2009 – 2014 – 2025

https://old.reddit.com/r/robotics/comments/1qp7z15/dexterous_robotic_hands_2009_2014_2025/
1•gmays•22m ago•0 comments

Interop 2025: A Year of Convergence

https://webkit.org/blog/17808/interop-2025-review/
1•ksec•32m ago•1 comments

JobArena – Human Intuition vs. Artificial Intelligence

https://www.jobarena.ai/
1•84634E1A607A•36m ago•0 comments

Concept Artists Say Generative AI References Only Make Their Jobs Harder

https://thisweekinvideogames.com/feature/concept-artists-in-games-say-generative-ai-references-on...
1•KittenInABox•39m ago•0 comments

Show HN: PaySentry – Open-source control plane for AI agent payments

https://github.com/mkmkkkkk/paysentry
1•mkyang•41m ago•0 comments

Show HN: Moli P2P – An ephemeral, serverless image gallery (Rust and WebRTC)

https://moli-green.is/
1•ShinyaKoyano•51m ago•0 comments

The Crumbling Workflow Moat: Aggregation Theory's Final Chapter

https://twitter.com/nicbstme/status/2019149771706102022
1•SubiculumCode•55m ago•0 comments

Pax Historia – User and AI powered gaming platform

https://www.ycombinator.com/launches/PMu-pax-historia-user-ai-powered-gaming-platform
2•Osiris30•56m ago•0 comments

Show HN: I built a RAG engine to search Singaporean laws

https://github.com/adityaprasad-sudo/Explore-Singapore
2•ambitious_potat•1h ago•1 comments

Scams, Fraud, and Fake Apps: How to Protect Your Money in a Mobile-First Economy

https://blog.afrowallet.co/en_GB/tiers-app/scams-fraud-and-fake-apps-in-africa
1•jonatask•1h ago•0 comments

Porting Doom to My WebAssembly VM

https://irreducible.io/blog/porting-doom-to-wasm/
2•irreducible•1h ago•0 comments

Cognitive Style and Visual Attention in Multimodal Museum Exhibitions

https://www.mdpi.com/2075-5309/15/16/2968
1•rbanffy•1h ago•0 comments

Full-Blown Cross-Assembler in a Bash Script

https://hackaday.com/2026/02/06/full-blown-cross-assembler-in-a-bash-script/
1•grajmanu•1h ago•0 comments

Logic Puzzles: Why the Liar Is the Helpful One

https://blog.szczepan.org/blog/knights-and-knaves/
1•wasabi991011•1h ago•0 comments

Optical Combs Help Radio Telescopes Work Together

https://hackaday.com/2026/02/03/optical-combs-help-radio-telescopes-work-together/
2•toomuchtodo•1h ago•1 comments

Show HN: Myanon – fast, deterministic MySQL dump anonymizer

https://github.com/ppomes/myanon
1•pierrepomes•1h ago•0 comments

The Tao of Programming

http://www.canonical.org/~kragen/tao-of-programming.html
2•alexjplant•1h ago•0 comments

Forcing Rust: How Big Tech Lobbied the Government into a Language Mandate

https://medium.com/@ognian.milanov/forcing-rust-how-big-tech-lobbied-the-government-into-a-langua...
4•akagusu•1h ago•1 comments

PanelBench: We evaluated Cursor's Visual Editor on 89 test cases. 43 fail

https://www.tryinspector.com/blog/code-first-design-tools
2•quentinrl•1h ago•2 comments

Can You Draw Every Flag in PowerPoint? (Part 2) [video]

https://www.youtube.com/watch?v=BztF7MODsKI
1•fgclue•1h ago•0 comments

Show HN: MCP-baepsae – MCP server for iOS Simulator automation

https://github.com/oozoofrog/mcp-baepsae
1•oozoofrog•1h ago•0 comments

Make Trust Irrelevant: A Gamer's Take on Agentic AI Safety

https://github.com/Deso-PK/make-trust-irrelevant
9•DesoPK•1h ago•5 comments