Python 3.11: A Guided Tour Through Code Transcripts
Chapter: Python 3.11 Performance
Lecture: Specializing Adaptive Interpreter

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So how exactly is Python 3.11 40% faster than just the previous version? Well, it starts with something that was called the Shannon plan,
0:13 as in Mark Shannon had this plan to make python five times faster over five years along those lines.
0:22 The idea was every year to make an improvement. Kind of like the one we saw here. And if you compound that over four or five releases,
0:30 then you end up with python being actually five times faster.
0:34 It's really exciting the progress they've already made, so five times faster than a couple of years possible.
0:41 You want to hear more about the plan, a lot of the details of what they've been doing again,
0:46 there's a bunch of small things that we're not going to focus on and code here,
0:49 but there's a few big ones that we will. So if you want to hear about how they plan and
0:54 are making python this much faster. I did a nice interview with Mark Shannon and Guido van Rossum. you can check out the link here at the bottom,
1:03 This is talk python to me, episode 339. So this was before the 3.11 release. This is kind of the beginning of when 3.11 started development I think.
1:15 So, really, really cool to see what they're doing here and if you want to learn more about the
1:19 overall performance story, check this out. One of the important,
1:23 one of the most important pieces about making Python 3.11 faster is this specializing adaptive interpreter?
1:31 The idea is that normally we saw this with when we disassembled our python code previously we have these byte code
1:39 operations and usually what they do is they assume more or less nothing about the type information or the specific operations
1:48 available on an object. So if I'm adding some things you might have to go figure out well what types
1:56 are these and then what operations do we actually call to add them all?
2:00 These are floats and integers. I see. So here are the steps but if you knew in advance that
2:06 you were adding to floating point numbers, you could do that way faster. And similarly if you knew you're adding two lists together,
2:14 that's a totally different operation. Theoretically you could do that a lot faster.
2:20 And so this specializing adaptive interpreter starts out in this general way of just a traditional way python has worked and
2:27 then if it sees certain things that it knows about and it knows it can make faster,
2:31 it will replace those with adapted specialized bike code instructions that say don't just call the add operation but in fact
2:39 add to floating point numbers, which as I said would be a lot faster. So you can see this code highlighted here on the screen.
2:49 This is a project called specialist by Brandt Bucher here. He is on the screen next to me again, I interviewed him about this on talk python 381 you
2:58 can check that out. We're going to be playing with his project specialist which will let us look at some
3:05 existing code, see how the adaptive interpreter is treating it and seeing if we can make it any faster by
3:13 taking some advice and specializing or helping the specializer make special instructions where otherwise it couldn't.
3:21 So we're going to play with this in code next.


Talk Python's Mastodon Michael Kennedy's Mastodon