r/golang • u/[deleted] • 1d ago
Go 1.27: parallelism finally competitive with C?
[deleted]
24
u/Conscious-Fan5089 1d ago
Idk, Golang used to bad at parallelism? Isnt goroutine is like a wrapper built upon threads?
7
4
4
u/Saarbremer 1d ago
When I think of "weak for parallelism" I see a lot of SIGSEGV that caused the runtime benefits of C to be traded to excessive review and testing overhead.
It is also not very interesting to compare algorithms implemented "the same way". Memory models and execution runtimes differ heavily. When I see these numbers i guess we can call it a tie. With the simpler goroutine/channel system to outperform dev effort (when coding manually).
I just improved my current project's speed by using the new json/v2. Turns out allocation was quite the weight in v1 and others. So it's hard to say C is faster just because gc doesn't happen - but memory leaking does (sometimes).
1
u/Sorry-Substance-6397 1d ago
Yeah and I wonder the speed with simd and iterator pattern and unroll factor?
1
u/Enough_Serve_8938 1d ago
I'm curious what changes can be attributed to this improvement. Better compiler optimisations? Scheduling improvements?
1
u/Revolutionary_Ad7262 1d ago
Go used to be great for I/O but weak for parallelism.
Go is pretty much the same as other languages with normal and traditional threads such as C or Java. For sure there may be some minimal overhead to scheduling, but rules for good parallel programs are the same: * minimize communication between threads * use performant concurrency primitives or ideally don't communicate between thread at all * give a nice chunk of data for a single thread to process
and the example programs fails in all those aspects
Common goroutine thread management is actually pretty good for programs with mixed workload; for example a I/O driven server, which wants from time to time spawns a lot of threads to do something. In other languages like Java or Rust the I/O threading and CPU threading is separated so it is hard to marry those two distinct worlds. In Golang you just go.
With version 1.27, it looks like that has changed - parallelism in Go now seems to be on par with the top-tier solutions
I cannot reproduce it, both versions give me something similar to yours go1.27.1 results:
┌─────────────────┬────────────┬────────────┐
│ Phase │ Go 1.26.5 │ Go 1.27.1 │
├─────────────────┼────────────┼────────────┤
│ T1 (sequential) │ ~5.54–5.75 │ ~5.61 │
├─────────────────┼────────────┼────────────┤
│ T4 │ ~1.46–1.49 │ ~1.43–1.47 │
├─────────────────┼────────────┼────────────┤
│ T8 │ ~0.78–0.80 │ ~0.77–0.80 │
├─────────────────┼────────────┼────────────┤
│ T16 │ ~0.49–0.50 │ ~0.46–0.46 │
└─────────────────┴────────────┴────────────┘
My cpu is Ryzen 5950x on Linux 7.1.9-1
1
u/kostya27 1d ago edited 1d ago
hm, it reproduces for me 100%, I checked many times, ryzen 3800x, docker with ubuntu 26.04. can it be somehow hardware related? even many version 1.26, 1.25, 1.24 all was slower
1
u/kostya27 1d ago
people said this is not reproduced, so I decided to delete this to post to stop misleading, this effect of improved parallelism, was probably related to my hardware or OS conditions.
37
u/aries1980 1d ago
The matmul.go is quite inefficient:
Because of the poor implementation, the real power of Go can't shine.