Remix.run Logo
▲ pancakeguy 2 hours ago

garbage collection will almost certainly be a relic of the past surprisingly soon. Fundamentally it exchanges efficiency for readability & developer experience, to things that do not matter when using AI to write code.

▲pron 5 minutes ago | parent | next [-]

That is just wrong. Moving GCs were invented because they're more efficient than manual memory management. In fact, in his famous 1986 paper, Garbage Collection Can Be Faster Than Stack Allocation, Andrew Appel wrote: "It is easy to believe that one must pay a price in efficiency for this ease in programming… But this is simply not true."

The reason low-level languages don't use moving collectors despite their superior efficiency is because they must give up on some performance optimisations for the abillity to interact with the hardware or OS directly, and that means that pointers must be stable machine addresses (this is why you need a richer FFI layer in Java). Moving collectors work in many ways like arenas. They don't need to maintain free lists whenever an object is allocated or freed (in fact, they never free any object at all), and memory is freed in bulk. This is not the only performance that low-level languages leave on the table because above everything else they must be low level.

Every single language that can use moving collectors does (it's also a matter of resources; moving collectors are hard to implement, especially the modern pauseless ones).

Sadly, people who are not compiler or memory allocator engineers don't know that, so they believe "popular wisdom" disseminated by other non-experts.

▲titzer an hour ago | parent | prev | next [-]

No, manual memory management, with or without static ownership, is not inherently more efficient than GC. Bump pointer allocation is crazy fast. GC work is proportional to live data, not dead data. GC can do compaction and locality optimizations. Manual deallocation is proportional to dead data, unless you are doing bulk deallocation with regions. Stack allocation is crazy fast. It's a little beyond what state-of-the-art compilers do by default, but it's just pointer analysis that will also get better with AI optimizing and improving compilers.

▲paulddraper an hour ago | parent [-]

GC is fast.

GC is not memory efficient.

If a primary concern is optimizing memory usage, you will avoid GC languages.

▲pron 10 minutes ago | parent [-]

That is not so simple. First, the differences among different GCs are larger than between some GCs and no GC. Second, moving GCs - of the kind used in HotSpot (as well as V8 and .NET), but not Go or Python (which are as different from each other as they are from moving GCs) - do, indeed have a higher memory utilisation, but it's not necessarily inefficient, because it comes into effect when CPU is under higher pressure than RAM. RAM and CPU are not independent resources; the most basic way to think about this is that your machine is exhausted when the first of CPU and RAM is exhausted. For example, I can take your car battery or I can take your petrol, but if I take your car battery when you don't have petrol, I'm not impacting your use of the car, so I'm not really creating any "inefficiency".

More here: https://youtu.be/xr73mR7ii9M

▲hashmash an hour ago | parent | prev | next [-]

Implementing efficient concurrent algorithms without a tracing collector is quite difficult, and it often requires the use of hazard pointers or epochs. Both act like mini collectors, and they also require special tuning.

Unless you want AI generated code to be single threaded and not take advantage of multiple cores, some form of collector is still required. If you want to avoid heap fragmentation issues, a compacting collector is generally recommended.

▲sealWithIt 2 hours ago | parent | prev | next [-]

On the one hand, I agree with you; on the other, I also find reasonable that lower cognitive load may keep justifying the existence of GC-based languages even for AI.

▲jeffbee an hour ago | parent | prev | next [-]

Can't agree. GC language platforms are more efficient in many ways. Look at the hoops that C allocators try to jump through just to get decent THP coverage which a compacting GC gets essentially for free.

▲quotemstr an hour ago | parent | prev | next [-]

Why would you think that malloc/free style memory management is more efficient? Both functions can be quite expensive, and they work synchronously. GCes give you compaction, compressed pointers, and bump pointer young generation operation as well as offloading allocation machinery to threads other than your business logic one. It's manual memory management that's going the way of the dinosaur, and the current interest in manual memory management is a fad.

▲xxpor 2 hours ago | parent | prev | next [-]

Disagree. Maybe the naive business app use case will, but there are plenty of places where you want to implement effective GC regardless. Anywhere you batch frees to avoid calling it in a hot path is a GC. So it's not _always_ an efficiency sacrifice. Or, a different perspective is you always have to ask "efficient with what resource?" CPU time efficiency vs memory efficiency for example (an interesting case where the _money efficiency_ has obviously moved severely in the past year!).

▲ogogmad 2 hours ago | parent | prev | next [-]

If true, it's sad. So much work and so much accumulated wisdom. It's like seeing a cathedral built by thousands of hands over dozens of years collapse in an earthquake.

▲jitix 2 hours ago | parent [-]

Disagree, we need to move ahead with progress.

Hobby and domain specific languages may still use GC but getting rid of the concept of GC is the right direction, along with removing different ways of doing things in a programming language. Go was right when it forced developers to use only pattern for loops, one pattern for error handling, etc.

▲titzer an hour ago | parent [-]

Memory management is a resource issue that should be orthogonal to the logic of code. Moving away from GC is not the right direction for writing smaller, more concise, and more correct programs.

I don't think that making programs a lot more complicated because they have to prove a very specific memory management discipline is the right way to go.

▲jitix an hour ago | parent [-]

Programming languages are just an intermediate representation of the solution, just like bytecode or assembly.

With AI we don't need expressive programming languages for humans to read and understand at line-level details. Instead, we need stronger guardrails and fewer building blocks so that AI generates consistent solutions.

GC became poplar only because it was hard for programmers to keep track of memory management in languages like C and C++. And back then I was a huge proponent of GC based languages.

This is just a step along the same path that Go introduced. Many programmers switching from other languages complain about Go's restrictive and seemingly verbose syntax but once the benefits are realized the tradeoffs become worth it.

▲titzer 11 minutes ago | parent [-]

> GC became poplar only because it was hard for programmers to keep track of memory management in languages like C and C++. And back then I was a huge proponent of GC based languages.

As I said elsewhere in the thread, GC is not inherently less efficient than manual memory management, so I don't really agree with this. It's better for programmers and makes for more ergonomic and evolvable APIs.

GC is a pervasive, system-wide service that makes ownership and management orthogonal to program logic. It does this by being a runtime service that comes with some runtime cost. Even manual memory management comes with runtime cost--different ones.

> With AI we don't need expressive programming languages for humans

Actually I think it's completely the opposite. PL is for humans to understand algorithms. We need AIs to reduce their thinking to algorithms and then present their solutions as algorithms to us. When we want to communicate precisely, reason and understand precisely, we don't write prompts, we write and understand programs.

That's not really a popular opinion right now because so many people are excited to be freed from thinking and staring at shitty code, but that isn't how it's going to go down. Programs are proofs that something has been reduced to a deterministic algorithm instead of a sloppy, ill-defined prompt or skill.

And to that, I for one do not want to have the communication medium be littered with memory management nonsense.

▲IncreasePosts 2 hours ago | parent | prev [-]

Doesn't this assume infinite abundance of compute? For most problems, using a GC is probably easier for AI than to track everything manually(just like with humans). Similarly, we could probably ask AI to output everything in optimized assembler code, but it will almost certainly burn more tokens getting to a solution than if we allow it to write in python or some other HLL