News for hackers. Stuff that matters.
Re:Some Thoughts on Zig by jillesvangurp on Thursday July 21, 2022 @11:17PM (#32188077)
I work with garbage collected languages all the time. Do you know how much time I spend tuning garbage collection and worrying about its performance? None whatsoever. Honestly, it's not a thing and it's mostly fine.

GC mostly just works really well. Occasionally you get some poor performance and then you find that you are doing something silly and then you fix it and move on. Or you throw more hardware at the problem.

GC has a bad reputation but the reality is that there is a lot of software being written with languages that aren't exactly famous for even having a particularly good garbage collector. Python, ruby, go, etc. They are alright but certainly nowhere near best in class when it comes to garbage collection. If that matters to you, you can pick python and ruby implementations that have way better performance than the default implementations provide. But the thing is, it does not matter. It's genuinely not a problem for people using those languages.

I\ve used each of those languages and also use Kotlin both on the JVM and in the browser. So, you'd think I spend a lot of time obsessing about what the javascript garbage collector does in the browser or how to tune the jvm? Nope. I just let it do its thing. We have no garbage collect related issues. So why spend time on it?

My observation is that engineers love talking about optimization but rarely realize how expensive they are relative to just throwing more hardware at a problem. And the thing is, some modest hardware goes a long way these days. We run our Spring/Kotlin JVM servers on cheap vms in Google cloud and in another data center using openstack. 2GB and one VCPU. About 25$ per month. That's around 10 minutes of my time at my freelance rate. Those are European rates, not Silicon Valley rates. Those are more like 3-5 minutes. We could go cheaper and I'm pretty sure I can make it run with half an GB if I work at the problem. But the savings are negligible and I like a little safety margin. We have many issues but our hosting bills are pretty awesome. Cutting them in half is literally not worth more than 1-2 hours of my time per month.

I think it's great that C/C++ are getting some competition from modern languages now. Rust has a pretty innovative borrowing mechanism and it seems to genuinely be better at certain things that have been the exclusive domain for heavily optimized C/C++ systems for decades. That's great. Zig seems like the more reasonable choice for people that just want something simple that works that isn't ancient and awkward like C but gets you ballpark in the same league in terms of performance. I learned C a long time ago and I love Linux. But the never ending exploits and security problems are a thing that I just don't need in my own projects. Having a garbage collector and some other safety has a tiny cost but eliminates whole classes of bugs and exploits. Completely worth it IMHO.

Re:Some Thoughts on Zig by throwaway17_17 on Thursday July 21, 2022 @11:28PM (#32188157)
I don’t disagree that various automatic memory management strategies can be very effective and efficient along various metrics. However, there are cases where ‘throwing more hardware’ at a problem is not a viable solution. Typical examples, that I think are broadly understood and commercially available, are soft-real-time simulations with advanced graphics and audio (fancy words for video games) and audio creation/performance/recording. These two areas are typically bound to be using a large portion of consumer computing device resources and GC is typically just too much overhead in certain performance metrics.
Re:Some Thoughts on Zig by jillesvangurp on Friday July 22, 2022 @01:07AM (#32188736)
You are not wrong of course. But it's interesting to see many commercial 3d gaming engines use things like Lua, C# and other garbage collected languages as the main way for game developers to use their engines. I grew up in an era where all that stuff was done in assembly. That stopped being a thing decades ago.

The vast majority of commercial software development can use off the shelf native components and pair them with garbage collected languages these days.

Re:Some Thoughts on Zig by suremarc on Friday July 22, 2022 @12:42AM (#32188599)
My company offers a data feed over WebSocket that could reach 70MB/s if we allowed you to subscribe to the entire feed at once (we don’t). No one ever planned for it to handle that much data, but here we are. Because WebSocket servers do not scale horizontally we had to consume the entire feed on one machine. (Edit: ofc you can scale the # of clients handled, but not the data throughput!)

Initially our Go app could only manage reading 10MB/s from Kafka, which is pretty sad. After switching from Shopify’s “Sarama” Go library to librdkafka (a Kafka client written in C), as well as some other arcane optimizations, we were able to 20x our throughput and handle up to 200MB/s, despite the overhead of interop between C and Go. On top of this, we used a library that wrapped librdkafka in Go bindings (confluent-kafka-go) and it turned out to have a much simpler interface than Sarama, in addition to it outperforming Sarama 20x.

While we didn’t end up rewriting the thing in Rust, we did end up leveraging a library written in C for major performance wins, in a case where scaling out was not possible. And let us also remember that even when scaling horizontally is possible, it is not necessarily even desirable in all circumstances: distributed systems, aside from introducing some amount of overhead, are basically Pandora’s box wrt. failure modes.

Re:Some Thoughts on Zig by jillesvangurp on Friday July 22, 2022 @01:03AM (#32188710)
Go is nice but it certainly has its limitations. I've seen heavily optimized jvm based things run circles around the kind of numbers you are talking about. 70 MB/s is not a number that should scare anyone running things like Kafka at scale.

I've worked with Elasticsearch clusters indexing close to a million documents per second from kafka. That takes a lot of CPU, memory, bare metal, etc. and it taxes the JVM garbage collection quite a bit. But it can be done. We basically maxed out CPUs across 30 or so nodes. Basically, when you get close to maxing out the disk IO, you know you are doing a decent job.

People reach for C for a lot of reasons. And not always the right reasons. But if it works, it works. A big reason seems to simply be that interfacing with it from various other languages is pretty straightforward. That's why python developers don't worry about performance. They can always plug in something native if it becomes an issue.

Re:Some Thoughts on Zig by suremarc on Friday July 22, 2022 @09:19AM (#32191599)
Again, scaling out to 30 nodes was not an option for us. It had to run on a single machine, unlike the rest of our data pipeline. While 200MB/s is nowhere near the theoretical limit of our hardware, it is near what Kafka’s stress testing tools achieved in the same setup, particularly with our record size (100 bytes).
Re:Some Thoughts on Zig by pjmlp on Friday July 22, 2022 @02:18AM (#32189107)
I am quite sure those arcane C optimizations are also possible in Go, it is a matter to learn how to properly use value types and the unsafe package.
Re:Some Thoughts on Zig by suremarc on Friday July 22, 2022 @09:23AM (#32191638)
I meant that we did optimizations in Go, on top of using a Kafka client written in C. When language constructs like channels degrade performance, and when goroutine scheduling takes 20% of your cpu time, it begs the question of whether you’re using the right tool for the job. If you are using unsafe to thwart the garbage collector, this is probably even more true.
Re:Some Thoughts on Zig by pjmlp on Friday July 22, 2022 @10:45AM (#32192393)
Same reasoning applies to C when using inline Assembler then.
Re:Some Thoughts on Zig by pverghese on Thursday July 21, 2022 @11:45PM (#32188274)
But zig can also use a GC if you want that as an allocator. As a proof of concept, libgc bindings were made by someone for zig. Very easy to use. Zig just allows you to use whatever memory management technique you need for the problem at hand
Re:Some Thoughts on Zig by pcwalton on Thursday July 21, 2022 @11:29PM (#32188163)
For what it's worth, I totally agree with you that GC is a perfectly reasonable memory management solution for most apps. "GC is bad" is not the takeaway anyone should have from new systems languages like Rust and Zig.
Re:Some Thoughts on Zig by chriskrycho on Thursday July 21, 2022 @11:47PM (#32188282)
Thirded. I think “pick a GC lang” is an eminently reasonable default stance! I use JS/TS all day every day and am on record on the main ongoing Rust podcast just a few weeks ago saying most folks shouldn’t be teaching for Rust just because. There are things which require it, though, and cases where even if it isn’t a hard requirement it makes a big difference in experience whether you have to boot a VM or not! I also think there’s a high value to really great performance even in cases which don’t demand it, but in those cases it’s really a matter of whether and how the productivity trade offs work in your specific context with your specific team.
Re:Some Thoughts on Zig by throwawaymaths on Friday July 22, 2022 @01:07AM (#32188727)
There are applications where you cannot have a garbage collector. The software on the PLC that controls when a saw stops itself and doesn't slice your finger. This would be horrible if a GC pass happened during this. I don't think realtime rust is a particularly fun idea, either, though you could certainly give runtime limits at compile time I suspect the macro system will make debugging timings on such code difficult if you ever need to use "other people's code"... One reason why I'm unsure about crypto in rust.
Re:Some Thoughts on Zig by pjmlp on Friday July 22, 2022 @02:16AM (#32189100)
Same here, specially since many GC languages also offer the capabilities to deal with value types, and if it really needs to come down to it, manual memory management.

Somehow it gets lost in the discussions as everyone associates their GC experience with Python or whatever.