News for hackers. Stuff that matters.
Re:Dismissing Python Garbage Collection at Instagram by stcredzero on Tuesday January 17, 2017 @07:24PM (#13422908)
It's basically "cheating" at GC by exploiting a very narrow use case. I saw a trick like this at Smalltalk Solutions in 2000 with a 3D game debugging tool. The "GC" actually simply threw everything away for each frame tick.

Someone needs to come up with something like a functional language based on a trick like this. Or maybe a meta-language akin to RPython, so people can write domain specific little languages for doing things like serving web requests, combined with domain specific "cheating" GC that can get away with doing much less work than a full general purpose GC.

Couldn't a pure functional programming environment be structured to allow for such GC "cheating?"

Re:Dismissing Python Garbage Collection at Instagram by true_religion on Wednesday January 18, 2017 @09:47AM (#13426618)
ErlangVM's GC does exactly this. Memory is scoped in a closure around a process, and any time the process goes down all its memory its thrown away.

Also anytime a functions scope terminates, all its memory immediately goes away.

This can be done because its a functional language with immutable data structures.

Re:Dismissing Python Garbage Collection at Instagram by dsp1234 on Wednesday January 18, 2017 @02:26PM (#13429483)
I work in VBScript inside of classic ASP and the statement, "Also anytime a functions scope terminates, all its memory immediately goes away.", is true there. I doubt anyone would suggest that VBScript is a functional language with immutable data structures.

Additionally, all memory used by a page is cleaned up when the page is finished processing. This has to do with "Memory is scoped" more than immutable data structures.

Re:Dismissing Python Garbage Collection at Instagram by philosopheer on Monday January 23, 2017 @03:07PM (#13465461)
I think you mean memory usage is lexically scoped because no pointers to blocks are saved or returned? I think, and didn't really want to think harder, just thought in the same sense that functional brings some useful baggage with it, so does lexical scope.
Re:Dismissing Python Garbage Collection at Instagram by toast0 on Wednesday January 18, 2017 @04:51PM (#13430634)
> Also anytime a functions scope terminates, all its memory immediately goes away.

I don't think this is accurate; those values remain until GC is triggered for the process or the process terminates.

Re:Dismissing Python Garbage Collection at Instagram by PeCaN on Wednesday January 18, 2017 @05:13PM (#13430850)
Erlang's GC is the perfect example of ‘work smarter, not harder’. It's not a particularly advanced GC, it just does so little work that it's soft-real-time capable.

As usual, excellent prog21 article: http://prog21.dadgum.com/16.html (I miss prog21 already…)

Re:Dismissing Python Garbage Collection at Instagram by white-flame on Wednesday January 18, 2017 @02:46PM (#13429649)
The article didn't read that way to me.

The GC is a fallback mechanism to catch any refcounting loops, but the reference counting is still in force, so non-looped objects still do get collected.

When the GC runs, everything gets touched. Without it, the refcounting still hits some shared objects, but this is reduced enough to be worth it, and the heap doesn't grow without bounds.

Re:Dismissing Python Garbage Collection at Instagram by hyperpape on Wednesday January 18, 2017 @05:43PM (#13431117)
It sounds a bit like you're describing region based memory management. https://en.wikipedia.org/wiki/Region-based_memory_management
Re:Dismissing Python Garbage Collection at Instagram by chubot on Wednesday January 18, 2017 @01:32PM (#13428900)
I'm not sure why you would call it cheating -- it seems like a very principled engineering decision to me.

Even if you never deploy, it's not like Python processes will run forever if you have have GC on. Big deployments usually recycle their processes regularly. Why wouldn't you? There's no downside once you have a big enough cluster.

I recall hearing that YouTube also runs with GC off, but I don't have a source for that.

Re:Dismissing Python Garbage Collection at Instagram by mannykannot on Thursday January 19, 2017 @08:20AM (#13435523)
I don't think anything pejorative is intended, but it is a bit like taking out a loan with no intention of repaying.

Another way of looking at it is that you are optimizing away a feature that Python needs in order to be a general-purpose language, but that is not needed for your purpose.

Re:Dismissing Python Garbage Collection at Instagram by chubot on Thursday January 19, 2017 @12:15PM (#13437394)
As long as you have the build infrastructure to support patched versions of Python, and can run multiple ones, I don't see the problem.

When you're running at scale like Instagram, it's inevitable that you need to do stuff like this. You're just pushing the limits of what open source software has been tested for.

I think this solution is a hack in the good sense... in particular because you are taking something away rather than adding crap on top, which is the typical solution. I wouldn't be as impressed if they came up with a fancy new GC that took 18 months to write and only worked for their workload. That would be the wrong way of thinking about the problem.

Re:Dismissing Python Garbage Collection at Instagram by stcredzero on Wednesday January 18, 2017 @02:03PM (#13429254)
I'm not sure why you would call it cheating -- it seems like a very principled engineering decision to me.

I like sounding "bad."

Re:Dismissing Python Garbage Collection at Instagram by asabil on Wednesday January 18, 2017 @07:49AM (#13425950)
Re:Dismissing Python Garbage Collection at Instagram by zaphar on Wednesday January 18, 2017 @09:25AM (#13426451)
I immediately thought of BEAM while reading this.
Re:Dismissing Python Garbage Collection at Instagram by Paul-ish on Wednesday January 18, 2017 @05:21PM (#13430916)
I think C++ and Rust have reference counting objects that can't collect cycles. Add that with an arena allocator and it sounds close to what you are describing. It's more explicit though, whereas Python does the reference counting for you here.
Re:Dismissing Python Garbage Collection at Instagram by nonsince on Wednesday January 18, 2017 @01:40PM (#13429004)
You could have a general-purpose "heap" interface that controls allocation. This would mean that you could control allocation space (for games this is really useful), and tearing down the the heap would tear down its owned objects. You could either hand out weak pointers or statically tie the lifetime to the lifetime of the heap, like Rust does.
Re:Dismissing Python Garbage Collection at Instagram by owaislone on Wednesday January 18, 2017 @04:54PM (#13430657)
I'm stupid so I don't know better but I think Go's new proposed GC is supposed to do something similar. Throw away everything that was created in a go-routine once the go-routine exits.
Re:Dismissing Python Garbage Collection at Instagram by bastawhiz on Wednesday January 18, 2017 @01:19PM (#13428733)
PHP works very similarly to what they describe in the post. It has a garbage collector that's effectively reference counting, but the whole heap just gets trashed at the end of every request.
Re:Dismissing Python Garbage Collection at Instagram by jeffasinger on Wednesday January 18, 2017 @03:17PM (#13429905)
It's not functional, and not automatic but Rust has an arena type which supports very fast allocation and de-allocation, with the restriction that de-allocation has to happen all at once.