Most active commenters
  • pebal(4)
  • kelseyfrog(4)
  • steveklabnik(3)

←back to thread

Four Years of Jai (2024)

(smarimccarthy.is)
166 points xixixao | 33 comments | | HN request time: 2.69s | source | bottom
Show context
pcwalton ◴[] No.43726315[source]
> I’d be much more excited about that promise [memory safety in Rust] if the compiler provided that safety, rather than asking the programmer to do an extraordinary amount of extra work to conform to syntactically enforced safety rules. Put the complexity in the compiler, dudes.

That exists; it's called garbage collection.

If you don't want the performance characteristics of garbage collection, something has to give. Either you sacrifice memory safety or you accept a more restrictive paradigm than GC'd languages give you. For some reason, programming language enthusiasts think that if you think really hard, every issue has some solution out there without any drawbacks at all just waiting to be found. But in fact, creating a system that has zero runtime overhead and unlimited aliasing with a mutable heap is as impossible as finding two even numbers whose sum is odd.

replies(4): >>43726355 #>>43726431 #>>43727184 #>>43731326 #
1. sph ◴[] No.43726355[source]
The faster computers get, the more the GC problem is way overblown apart from super-low-latency niches. Even AAA games these days happily run on GC languages.

There is a prominent contributor to HN whose profile says they dream of a world where all languages offer automatic memory management and I think about that a lot, as a low-level backend engineer. Unless I find myself writing an HFT bot or a kernel, I have zero need to care about memory allocation, cycles, and who owns what.

Productivity >> worrying about memory.

replies(4): >>43726479 #>>43726679 #>>43729279 #>>43729921 #
2. lifthrasiir ◴[] No.43726479[source]
GC doesn't exactly solve your memory problem; it typically means that your memory problem gets deferred quite far until you can't ignore that. Of course it is also quite likely that your program will never grow to that point, which is why GC works in general, but also why there exists a desire to avoid it when makes sense.
replies(3): >>43726569 #>>43726586 #>>43730602 #
3. sph ◴[] No.43726569[source]
That’s fair, no resource is unlimited. My point is that memory is usually the least of one’s problem, even on average machines. Productivity and CPU usage tend to be the bottleneck as a developer and a user. GC is mostly a performance problem rather than a memory one, and well-designed language can minimize the impact of it. (I am working on a message-passing language, and only allowing GC after a reply greatly simplifies the design and performance characteristics)
replies(1): >>43738357 #
4. mjburgess ◴[] No.43726586[source]
Not sure why you're down-voted, this is correct.

In games you have 16ms to draw billion+ triangles (etc.).

In web, you have 100ms to round-trip a request under abitarily high load (etc.)

Cases where you cannot "stop the world" at random and just "clean up garbage" are quite common in programming. And when they happen in GC'd languages, you're much worse off.

replies(2): >>43726627 #>>43730012 #
5. immibis ◴[] No.43726627{3}[source]
Java's ZGC claims O(1) pause time of 0.05ms.

(As with any low-pause collector, the rest of your code is uniformly slower by some percentage because it has to make sure not to step on the toes of the concurrently-running collector.)

replies(2): >>43727026 #>>43729288 #
6. withoutboats3 ◴[] No.43726679[source]
This is exactly the attitude this blog post spends its first section pretty passionately railing against.
replies(1): >>43727958 #
7. Ygg2 ◴[] No.43727026{4}[source]
> Java's ZGC claims O(1) pause time of 0.05ms

In practice it's actually closer to 10ms for large heaps. Large being around 220 GB.

8. ◴[] No.43727958[source]
9. jplusequalt ◴[] No.43729279[source]
>Even AAA games these days happily run on GC languages.

Which games are these? Are you referring to games written in Unity where the game logic is scripted in C#? Or are you referring to Minecraft Java Edition?

I seriously doubt you would get close to the same performance in a modern AAA title running in a Java/C# based engine.

replies(3): >>43730195 #>>43730237 #>>43730302 #
10. riku_iki ◴[] No.43729288{4}[source]
With Java, the issue is that each allocated object carries significant memory footprint, as result total memory consumption is much higher compared to C++: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
replies(1): >>43737053 #
11. Narishma ◴[] No.43729921[source]
> Even AAA games these days happily run on GC languages.

You can recognize them by their poor performance.

12. Tomte ◴[] No.43730012{3}[source]
That's why it's good that GC algorithms that do not "stop the world" have been in production for decades now.
replies(1): >>43732292 #
13. Jasper_ ◴[] No.43730195[source]
Unreal Engine has a C++-based GC.

https://dev.epicgames.com/documentation/en-us/unreal-engine/...

14. steveklabnik ◴[] No.43730237[source]
Unreal Engine has a GC.

You're right that there is a difference between "engine written largely in C++ and some parts are GC'd" vs "game written in Java/C#", but it's certainly not unheard of to use a GC in games, pervasively in simpler ones (Heck, Balatro is written in Lua!) and sparingly in even more advanced titles.

replies(2): >>43730382 #>>43754526 #
15. neonsunset ◴[] No.43730302[source]
C#? Maybe. Java? Less likely.
16. tuveson ◴[] No.43730382{3}[source]
I think Balatro uses the Love2d engine which is in C/C++.
replies(1): >>43730531 #
17. steveklabnik ◴[] No.43730531{4}[source]
Sure, but you write games in it in Lua. That Love2d is implemented in C++ (GitHub says like 80% C++ and 10% C) doesn't mean that you're writing the game in it. In my understanding, Love2d uses reference counting (which is still GC) for its own stuff, and integrates those into Lua's tracing GC.
18. throwawaymaths ◴[] No.43730602[source]
eh, there are GC languages famous for high uptimes and deployed in places where it "basically runs forever with no intervention", so in practice with the right GC and application scope, "deferring the concern till the heat death of the universe" (or until a CVE forces a soft update) is possible.
replies(1): >>43733288 #
19. pebal ◴[] No.43732292{4}[source]
There are none, at least not production grade.
replies(2): >>43732497 #>>43735137 #
20. kelseyfrog ◴[] No.43732497{5}[source]
There are none, or you're not aware of their existence?
replies(1): >>43732755 #
21. pebal ◴[] No.43732755{6}[source]
There are no production implementations of GC algorithms that don't stop the world at all. I know this because I have some expertise in GC algorithms.
replies(1): >>43733113 #
22. kelseyfrog ◴[] No.43733113{7}[source]
I'm curious why you don't consider C4 to be production grade
replies(1): >>43735299 #
23. lifthrasiir ◴[] No.43733288{3}[source]
That's exactly why I said "it is also quite likely that your program will never grow to that point". Of course you need non-trivial knowledge to determine whether your application and GC satisfy that criteria.
24. worthless-trash ◴[] No.43735137{5}[source]
I have heard (and from when I investigated) erlangs GC is 'dont stop the world'.

Maybe my definition is bad though.

25. pebal ◴[] No.43735299{8}[source]
Azul C4 is not a pauseless GC. In the documentation it says "C4 uses a 4-stage concurrent execution mechanism that eliminates almost all stop-the-world pauses."
replies(1): >>43738741 #
26. igouy ◴[] No.43737053{5}[source]
The benchmarks game shows memory use with default GC settings (as a way to uncover space-time tradeoffs), mostly for tiny tiny programs that hardly use memory.

Less difference — mandelbrot, k-nucleotide, reverse-complement, regex-redux — when the task requires memory to be used.

Less with GraalVM native-image:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

replies(1): >>43737112 #
27. riku_iki ◴[] No.43737112{6}[source]
> Less difference — mandelbrot, k-nucleotide, reverse-complement, regex-redux — when the task requires memory to be used.

yes, I referred to benchmarks with large memory consumption, where Java still uses from 2 to 10(as in binary tree task) more memory, which is large overhead.

28. charleslmunger ◴[] No.43738357{3}[source]
>My point is that memory is usually the least of one’s problem, even on average machines.

The average machine a person directly interacts with is a phone or TV at this point, both of which have major BoM restrictions and high pixel density displays. Memory is the primary determination of performance in such environments.

On desktops and servers, CPU performance is bottlenecked on memory - garbage collection isn't necessarily a problem there, but the nature of separate allocations and pointer chasing is.

On battery, garbage collection costs significant power and so it gets deferred (at least for full collections) until it's unavoidable. In practice this means that a large amount of heap space is "dead", which costs memory.

Your language sounds interesting - I've always thought that it would be cool to have a language where generational GC was exposed to the programmer. If you have a server, you can have one new generation arena per request with a write barrier for incoming references from the old generation to the new. Then you could perform young GC after every request, only paying for traversal+move of objects that survived.

29. kelseyfrog ◴[] No.43738741{9}[source]
Except the documentation says

> C4 differentiates itself from other generational garbage collectors by supporting simultaneous-generational con- currency: the different generations are collected using concurrent (non stop-the-world) mechanisms

replies(1): >>43739876 #
30. pebal ◴[] No.43739876{10}[source]
It doesn't matter at all. C4 uses STW.
replies(1): >>43740239 #
31. kelseyfrog ◴[] No.43740239{11}[source]
I wish I could have learned more from this interaction than it doesn't matter.
32. jplusequalt ◴[] No.43754526{3}[source]
Thanks for the Rust book!
replies(1): >>43755742 #
33. steveklabnik ◴[] No.43755742{4}[source]
You're welcome!