Chris Lattner
๐ค SpeakerAppearances Over Time
Podcast Appearances
This is usually the two design patterns.
If you look in PyTorch, for example, this is cloning a tensor.
Like there's a specific thing and you have to know where to call it.
And if you don't call it in the right place, you get these bugs and this is state of the art, right?
So a different approach, so it's used in many languages, so I've worked with it in Swift, is you say, okay, well, let's provide value semantics.
And so we want to provide the view that you get a logically independent copy, but we want to do that lazily.
And so what we do is we say, okay, if you pass something into a function, it doesn't actually make a copy.
What it actually does is it just increments a reference to it.
And if you pass it around, you stick it in your database, it can go in the database, you own it.
and then you come back out of the stack, nobody's copied anything, you come back out of the stack and then the caller lets go of it, well then you've just handed it off to the database, you've transferred it, and there's no copies made.
Now on the other hand, if your coworker goes and hands you a record and you pass it in, you stick it in the database, and then you go to town and you start modifying it, what happens is you get a copy lazily on demand.
And so what this does is gives you copies only when you need them.
And it also, so it defines away the bugs, but also generally reduces the number of copies in practice.
Yeah, so you need a couple of things.
So this concept has existed in many different worlds.
And again, it's not novel research at all.
The magic is getting the design right so that you can do this in a reasonable way.
And so there's a number of components that go into this.
One is when you're passing around.
So we're talking about Python and reference counting and the expense of doing that.