Latest / Talk Python To Me / #375: Python Language Summit 2022
Transcript
- 0:00Every year, the Python core developers and a few other key players in the Python ecosystem
- 0:04meet to discuss the pressing issues and important advancements
- 0:08at an event called the Python Language Summit.
- 0:11While Python is a community known for its openness,
- 0:14this meeting is typically held behind closed doors, mostly for efficiency's sake.
- 0:19On this episode, we'll give you a look behind that door.
- 0:23We have Alex Waygood here on this episode to break it down for us
- 0:26and give us a report from inside the Python Language Summit.
- 0:30This is Talk Python To Me, episode 375, recorded June 29th, 2022.
- 0:36Welcome to Talk Python To Me, a weekly podcast on Python.
- 0:53This is your host, Michael Kennedy.
- 0:54Follow me on Twitter where I'm @mkennedy and keep up with the show
- 0:58and listen to past episodes at talkpython.fm
- 1:01and follow the show on Twitter via at Talk Python.
- 1:04We've started streaming most of our episodes live on YouTube.
- 1:07Subscribe to our YouTube channel over at talkpython.fm/youtube
- 1:11to get notified about upcoming shows and be part of that episode.
- 1:16This episode is sponsored by Reflect.run.
- 1:19If you can browse the web, you can use Reflect.run to create sophisticated tests for your web app.
- 1:24And it's brought to you by Microsoft for Startups, Founders Hub.
- 1:29Get early stage support for your startup and build what you've been dreaming about.
- 1:35Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:38Do you need a great automatic speech-to-text API?
- 1:41Get human-level accuracy in just a few lines of code.
- 1:44Visit talkpython.fm/assemblyai.
- 1:46Alex, welcome to Talk Python To Me.
- 1:49Thank you.
- 1:50It's great to be on the show.
- 1:50Big fan of the podcast.
- 1:52There's so much going on with the Python Language Summit, especially this year.
- 1:55I think there's quite a renaissance of new ideas to sort of look at the foundations and the fundamentals of Python.
- 2:02And a lot of it has to do with speed in different aspects.
- 2:06Maybe that's through threading or through raw performance or reference counting garbage collection.
- 2:10And so we're going to dive into all those ideas and more by just talking about your coverage of the Python Language Summit 2022.
- 2:18It's going to be super fun.
- 2:20But before we get to that, let's get to your story.
- 2:22How did you get into programming in Python?
- 2:23And how did you get inside the Language Summit anyway?
- 2:25Oh, yeah, sure.
- 2:26So I started programming actually only around two years ago.
- 2:30But my first line of code during the pandemic started off as a hobby.
- 2:34Still actually is a hobby.
- 2:36Had to have something to do while staying indoors.
- 2:39Exactly.
- 2:39Yeah, so Python is my first language and I'm entirely self-taught.
- 2:43And yeah, once I started, couldn't stop.
- 2:46That's cool.
- 2:46What kind of things were you looking to build?
- 2:49Were you just looking to learn a language or did you have some idea of something you wanted to create?
- 2:52So I started, so I was doing a journalism master's at the time.
- 2:56And there's a sub-community of journal coders.
- 3:01So people who use programming languages to gather data, scrape the web to find stories, essentially.
- 3:08So I thought that sounded pretty cool.
- 3:10Yeah, that sounds very cool.
- 3:11Yeah, so I started learning Python to help with that.
- 3:15And then sort of started to realize I actually enjoyed Python quite a lot, just for its own sake.
- 3:21Started building, built a card game using Pygame.
- 3:25It was one of my first projects, which was a lot harder than I anticipated.
- 3:29All the first projects are.
- 3:30Oh, yeah.
- 3:31Yeah, definitely.
- 3:32And then built a bad website using Flask.
- 3:35And then eventually started contributing to open source.
- 3:39And that's about where I am now.
- 3:41Fantastic.
- 3:41Yeah, yeah.
- 3:42That's really cool.
- 3:43It's interesting that you bring up journalism.
- 3:45I had Carolyn Stransky on a little while ago, predated the pandemic.
- 3:50Is it?
- 3:51Did it?
- 3:52Yeah.
- 3:52Maybe not.
- 3:53I don't even know when the pandemic was.
- 3:55A couple of years ago.
- 3:56Anyway, we talked about Python.
- 3:58Looks like you just hit before the business started.
- 4:01Just before it really, really kicked it.
- 4:04Exactly.
- 4:05Yeah.
- 4:05We talked about Python and AI and journalism.
- 4:08And there's a ton of neat things that people are doing to sort of automate the act of gathering data and reporting on it, right?
- 4:17Yeah.
- 4:18No, it's a really cool space.
- 4:19Directly employed in journalism is my full-time job at the moment.
- 4:22But it's something I'd love to dip into again at some point.
- 4:26For sure.
- 4:26Yeah.
- 4:27Carolyn was talking about things like monitoring certain websites like the National Geography, whatever the foundation is there, that alerts people about earthquakes.
- 4:38And I would bring up details and sort of pre-fill.
- 4:42So like some folks in LA, like on the LA Times or something, would get an alert.
- 4:47There's an earthquake.
- 4:47Here's most of the details.
- 4:48Just put the details around it and hit publish, you know, within 10 minutes or whatever.
- 4:53That's pretty cool.
- 4:54A little beep and then go write your article now.
- 4:56One of my first projects I tried to do, again, biting off much more than I could chew, was there's a, in the UK, we have this body called Historic England, which catalogs England's old buildings and heritage assets.
- 5:10And I have this all online, but it's not like in an easily downloadable form.
- 5:13You know, you can't just like download the CSV of the National Heritage List.
- 5:17So I decided that I was going to try and scrape this from the website.
- 5:20Of course, the scraping is easy, but then the data cleaning is a nightmare.
- 5:25Because like there's no consistent format and some of it's from the 1950s and yeah, it's horrible.
- 5:29Well, it would have been cool if you could have gotten it right and shared it with everyone.
- 5:34I got, I got some way there, but yeah, it's way too, way too difficult for one man.
- 5:40Like just started learning a few months ago.
- 5:42Yeah.
- 5:43Yeah.
- 5:43Yeah.
- 5:43Of course.
- 5:44It's those kinds of projects that are really good for learning programming.
- 5:47You know, they're.
- 5:48Oh yeah.
- 5:48I learned a ton.
- 5:49Don't regret it at all.
- 5:50Yeah.
- 5:50You're like, here's my goal.
- 5:52And then you just start frantically searching for like, well, what are the steps I need?
- 5:56And then how do I make those steps happen in my programming language, Python in this case?
- 5:59And like, you might not normally care to figure out how do you parse a CSV file out of this,
- 6:04but you're going to have to do it now because you're trying to, you know, aggregate on, you know,
- 6:07add onto it, append onto it and so on.
- 6:09So yeah, those kinds of things are great, great projects.
- 6:12Cool.
- 6:12All right.
- 6:13Well, how'd you get into the Python language summit from a journalism anger, from the open
- 6:18source angle?
- 6:18What was, what's the story here?
- 6:20I was invited in the autumn, I think, to become a triage with CPython.
- 6:25So at that point I'd contributed a lot of docs, documentation fixes, just something I was pretty
- 6:32good at because of the journals and masters.
- 6:33You actually know how to write.
- 6:36So yeah, I do know.
- 6:37I'd also contributed code to a few modules at that point, a few small fixes to,
- 6:43I think, functools, enum.
- 6:46Yeah, a few standard lib modules.
- 6:47So I'd been invited by Ken Jin, who's one of the typing module maintainers to become a triage
- 6:55during the autumn.
- 6:55So that got me onto the CPython developers' Discord channel.
- 6:59And then in, I think it was February or March, there was a discussion there where a few cordels
- 7:05were asking who they were going to invite to become the blogger this year.
- 7:09You know, Alex does journalism.
- 7:11Yeah.
- 7:11I got this, I got this master's.
- 7:14I mean, could maybe I do it?
- 7:16And they said yes, which was very flattering.
- 7:19Yeah.
- 7:19Fantastic.
- 7:20And great of them.
- 7:22And I really, really appreciate it.
- 7:23So it's Ukash, Mayata, and Sentil this year who organized the Language Summit.
- 7:28So massive thanks to them for inviting me to be the blogger this year.
- 7:32I actually appreciate it.
- 7:33Yeah, that's great.
- 7:34You must have been also at PyCon then, I'm guessing, because if you're at the Language Summit,
- 7:38you're at PyCon.
- 7:39Yeah, what was your experience there?
- 7:40Was it a good time?
- 7:40Yeah, I had a blast.
- 7:42It was great.
- 7:43Yeah.
- 7:43It's awesome to meet all these people I've been, you know, doing up and sort of stuff
- 7:47with online for several months.
- 7:49Yeah.
- 7:50It was really cool.
- 7:51Cool.
- 7:51I really appreciate these conferences because there's people I work with or talk to in different
- 7:57ways through, you know, through GitHub, through Twitter, through the podcast.
- 8:01But you don't really get to see them in person because they're halfway around the world until
- 8:05you show up and have a beer together or hang out together.
- 8:08I think that was, I mean, the talks are fantastic.
- 8:10But yeah, that was definitely the best bit for me.
- 8:12Yeah, that's the same for me, actually.
- 8:15That's the thing that I dig the most.
- 8:16All right.
- 8:17Let's talk about the Language Summit.
- 8:18Sure.
- 8:18So maybe tell people really quickly, what is the Language Summit?
- 8:21Sure.
- 8:22The Language Summit is an event every year.
- 8:25It's just like a day or two days before PyCon itself starts.
- 8:29Most of PyCon is available to just like anybody who's interested in Python.
- 8:34The Language Summit is generally only available to like core developers and special guests.
- 8:39So it's a big exclusive.
- 8:41That's not because they want to be like secretive about what's happening in there.
- 8:45It's more so that it can just be a sort of frank conversation between trends, I think.
- 8:51Sort of.
- 8:52Yeah.
- 8:53Does that make sense?
- 8:53Yeah.
- 8:53I mean, it's where the business of planning out Python gets done, right?
- 8:58Yeah, exactly.
- 8:59Yeah.
- 8:59It's not the only place.
- 9:00We have our peps and we have other places where conversation happens.
- 9:04But it seems like one of the places where, you know, some of the ideas of the peps are discussed
- 9:09and there's a quick feedback loop amongst a lot of the core developers.
- 9:13Yeah, exactly.
- 9:14I think it's just, you know, get everybody together all in one small room, talk Python for the whole
- 9:19day and then see what comes out of it.
- 9:21Awesome.
- 9:21How many people show up there?
- 9:22How many core developers and other folks?
- 9:25Around 30 this year, I think.
- 9:27So mostly core developers, a few triagers and a few special guests.
- 9:33So Zach Hadfield-Dobbs, I think, from Hypothesis was there.
- 9:38Sam Colvin from Pydantic.
- 9:40So yeah, a few open source maintainers outside the Core Dev team as well.
- 9:45Right, right.
- 9:46Yeah.
- 9:46Yeah, Pydantic's interesting.
- 9:48Obviously a great library.
- 9:49It's interesting to me because it kind of, a lot of its meaningful functionality is in
- 9:55the way that it breaks with the tradition of Python, you know, in the same way, like type
- 10:00hints.
- 10:00Now all of a sudden don't just mean something, but like they are the core way in which that
- 10:04library works.
- 10:05Whereas like most of the time it's a suggestion or a hint as the name would suggest.
- 10:09Sure.
- 10:09Yeah, yeah.
- 10:10And in the way it's quite coercive as well.
- 10:13So you don't have to like, yeah.
- 10:14Yeah, for sure.
- 10:15It's, so he's a good guest to have because he's, he's both got a popular project and
- 10:19one that's kind of an outlier to some degree.
- 10:21Yeah.
- 10:21It's hugely popular, isn't it?
- 10:23Yeah, it sure is.
- 10:24We've got, you know, SQL model by Sebastian Ramirez, which is basically take Pydantic models
- 10:30on top of SQLAlchemy and you've got Beanie from Roman Wright and there's some other ones
- 10:36that are just like sort of using Pydantic as their, their layer, which is really cool.
- 10:41So obviously the reason we're chatting today is this year's summit was covered by Alex
- 10:45Waygood.
- 10:46That's awesome.
- 10:47That's me.
- 10:47Yeah.
- 10:47Yay.
- 10:48Nicely done.
- 10:49And so I, when I saw this article or series of articles, I guess you might say come out,
- 10:54I thought it was really fantastic because like I said, I think there's just so much that's
- 10:59exciting going on here.
- 11:01No, it's not.
- 11:02Well, we're going to change the language a little bit here or there, but there's, there's stuff
- 11:05that everyone's going to get.
- 11:06That's really huge stuff in that.
- 11:08Yeah.
- 11:08Yeah, absolutely.
- 11:10So I thought what we could do for our conversation is just go and order and just sort of chat
- 11:15through them.
- 11:15You can give me a sense of what it was like to be in the room.
- 11:18What are some of the main ideas of, of each of these?
- 11:21And we'll, we'll just chat about them.
- 11:22So the first one was a very exciting project by Sam Gross.
- 11:26Yes.
- 11:27Who I think works for Meta.
- 11:29Yeah.
- 11:29I think he does.
- 11:30Yeah.
- 11:30I think he does part of the Cinder stuff.
- 11:31Yeah.
- 11:31And this is Python without the GIL or, or no GIL.
- 11:35I don't think he's on the Cinder team, but, but yeah, he is working at Meta.
- 11:39Right.
- 11:39Okay.
- 11:40Cool.
- 11:41Yeah.
- 11:41There's other stuff from Cinder.
- 11:42We'll get to later.
- 11:43Yeah.
- 11:43But yeah, Python without the GIL or, you know, his, his no GIL story.
- 11:48There's been a, you know, from a historical perspective, we've had attempts to remove the
- 11:53gill or change the performance characteristics of the GIL and so on.
- 11:57And maybe let me just set the stage a little bit with this GIL or global interpreter lock
- 12:02for people listening.
- 12:03When I heard this, the global interpreter lock means you can only run one statement of Python
- 12:09at a time, even if it's happening in multiple threads.
- 12:12I thought, okay, well, this must be some odd constraint put on the language so that things
- 12:17like threading are easier for people.
- 12:19But as I learned more about it, the real purpose of the GIL has nothing to do with threading
- 12:24per se.
- 12:25It has to do with memory management.
- 12:27Yeah.
- 12:27Yeah.
- 12:27And so the way memory management happens in Python, at least in the primary first pass
- 12:33sense is it's reference counted.
- 12:34So everything, numbers, strings, classes, dictionaries, they all have a ref count.
- 12:39And if that ref count ever reaches zero, it gets deleted as long as there's no cycles.
- 12:43And the problem is if you're going to change that number on the object, normally you would
- 12:49have to do that in a thread safe way.
- 12:50You will lock it.
- 12:51But that turns out to slow single threaded Python down a lot when it's unneeded.
- 12:55And so the global interpreter lock is there to meant to basically allow for that reference
- 13:00counting to happen quickly in the single threaded case.
- 13:03And that made fantastic sense 30 years ago.
- 13:05Now that we're sitting here with our 16 and 32 core CPUs, all of a sudden, we might want
- 13:12to run more than one thread and get stuff done.
- 13:14You know what I mean?
- 13:14Yeah.
- 13:15That's the history of the GIL.
- 13:16And so there were other things like Larry Hastine.
- 13:21He was there, right?
- 13:22Yeah.
- 13:22Yeah.
- 13:23Just to interject for a second.
- 13:24It's really fun to see sort of how long a project has been to try to remove the GIL.
- 13:29You can go back 10 years ago and there's a talk by David Beasley on weird things going
- 13:35on with the GIL in 2010.
- 13:36And then I was writing this after the summit, looking through the archives, past language
- 13:43summit bloggers.
- 13:45I think there's like three successive years running where there's presentations about
- 13:49the latest project to remove the GIL.
- 13:51But like this time, it actually seems like it could happen.
- 13:53It's really cool.
- 13:54It could happen.
- 13:55Yeah, it certainly could.
- 13:56Sam Gross's work seems to be the most likely candidate.
- 14:00And all the other attempts, their challenges have been, yes, you might remove the GIL and you
- 14:05might make the parallel computing faster, but you're going to make single threaded Python
- 14:09so much slower that it's, we don't want to accept it, right?
- 14:13If you could say, well, you can use core, you can use all the cores on your machine, but
- 14:16now everything runs half as fast.
- 14:18That's not a huge benefit to a lot of people.
- 14:20Yeah.
- 14:21And especially because, because of the fact that the guild's been there for so long,
- 14:25the vast majority of Python code is with only one thread, right?
- 14:28So it's like, well, it could make your Python code faster, but only if you rewrote all of
- 14:33your code, which not many people want to do.
- 14:36True.
- 14:36The other major problem or challenge that is there is how does it work with the C extensions
- 14:42that are so important to making Python work well, right?
- 14:45NumPy and all those types of things, right?
- 14:48Yeah.
- 14:48So Larry Hastings was there and he worked on the Galectomy, which I think is still the
- 14:54best name of all these projects.
- 14:55The Galectomy.
- 14:56Yes, definitely.
- 14:58Yeah, but it sounds like he thinks that Sam's project is already farther than his.
- 15:03This portion of Talk Python To Me is brought to you by Reflect.run.
- 15:08Reflect is the fastest way to create end-to-end tests for your web app.
- 15:12Most of us have encountered flaky, unreliable tests over the years.
- 15:16For a lot of us, testing our code is painful, but it doesn't have to be.
- 15:20Reflect was created by developers who are tired of dealing with constant problems inherent in
- 15:25code-based testing tools for web apps.
- 15:27Reflect is an automated, no-code testing tool that enables you to shave countless hours off
- 15:32your end-to-end testing timeline.
- 15:34If you can browse the web, you can create sophisticated tests with Reflect.
- 15:39navigate to your site within Reflect's simulated browser and perform the actions you want to test.
- 15:43Reflect will auto-generate selectors and do the painstaking work of test creation and maintenance
- 15:49for you in minutes.
- 15:50Instead of creating and maintaining a separate code base for your tests, you can manage all of your tests within Reflect.
- 15:56Features include visual validation, efficient for debugging and eliminating weights, cross-browser testing, run tests across all modern browsers,
- 16:05including Safari, Chrome, Firefox, and Edge, and email and SMS validation.
- 16:10The best way to appreciate what Reflect can do for you is to see it in action.
- 16:14They put together a nice six-minute video you can watch at talkpython.fm/reflect dash video.
- 16:20That's reflect dash video.
- 16:21I encourage you to watch it and see how straightforward and composable their tool is to use.
- 16:26Once you're ready to try it out, sign up at talkpython.fm/reflect.
- 16:30And as a special offer for Talk Python listeners, you'll get a free t-shirt when you sign up through this link.
- 16:36That's talkpython.fm/reflect to see how easy web testing can be.
- 16:40The link's in your show notes.
- 16:41Thank you to reflect.run for supporting the show.
- 16:44Maybe tell us a bit about what Sam was proposing there.
- 16:48So yeah, Sam has got this fork of cPython where he has removed the GIL and it all works.
- 16:55I think, you know, there's still a few rough edges, but it all basically works essentially.
- 16:59So now he is looking to...
- 17:02So if you want to, you can try that right now.
- 17:03You can go and download Sam's blog, new gill, and most Python programs will run fine on it.
- 17:09That's it right there.
- 17:10Yeah.
- 17:10For those watching...
- 17:11Yeah, I'll put a link in the show notes.
- 17:12Yeah.
- 17:13People can check out the GitHub repo and it's just a fork of Python, of cPython, and then goes from there, right?
- 17:19Yeah.
- 17:19And now Sam is hoping to essentially create a separate mode of cPython that you can enable with a compiler flag,
- 17:27which would enable new GIL.
- 17:29So to get his changes merged into the cPython main branch, essentially.
- 17:33So that would mean you would have to build cPython separately in order to get a version of cPython when no GIL would work.
- 17:41So it wouldn't be like you'd be able to just open up the repo and go like, import no GIL.
- 17:46It wouldn't be quite that easy.
- 17:47Right, right.
- 17:48It is a bit of a hassle that it's literally a separate compilation step, a separate binary and so on.
- 17:56But maybe it could ship.
- 17:57Maybe the cPython distribution, if this really works out well, could be shipped with that.
- 18:03Like it could be a set of Python or Python 3 or whatever you type.
- 18:08It could be Python ng or something like that.
- 18:11You know, like some extra command you can run.
- 18:13But at least it would be nice at least if you didn't have to literally go find a different installer and try to avoid the name clashes of what Python means, you know?
- 18:21Yeah.
- 18:21Yeah, for sure.
- 18:22And this is a change from his original proposal.
- 18:24So his original proposal was for a runtime flag.
- 18:27So that would mean that you would be able to, I don't know.
- 18:30I don't know how exactly it would work, but do something like import no GIL.
- 18:33Yeah.
- 18:34And reading your write up here, it sounded like Sam has come to the conclusion that there's too many differences for a runtime flag to make sense.
- 18:41And it's got to be a compiled type of thing.
- 18:44Exactly.
- 18:45So yeah, that was his proposal.
- 18:47How was the reception?
- 18:47There were a lot of questions for Sam.
- 18:50So I think there were, I think like a few of the other proposal presentations finished under time later on in the summit.
- 18:58And then we went back and asked some more questions to Sam because we still have questions.
- 19:02Yeah.
- 19:03So I think everybody in the room definitely knew.
- 19:06So like it's crazy.
- 19:07If you look at the viewing figures for these blogs, like the blog on no GIL is off the charts in terms of how many people have clicked on it and read it.
- 19:17Interesting.
- 19:18Okay.
- 19:19So it's like, the last time I checked, it was like 40,000 people had read the no GIL article and the next highest was 5,000 people.
- 19:26Wow.
- 19:27There was a huge amount of interest in this feature and the people in the room knew that there was a huge amount of interest in this feature.
- 19:32So I think there's a lot of interest in making this work if it can be made to work.
- 19:36Sure.
- 19:37But there's just a lot of complications about how to get that.
- 19:40So there were a lot of people asking what exactly the plan is here because it's this huge project that Sam's been working on for months and months.
- 19:49And how do you merge that into cPython?
- 19:52You know, you obviously can't have one PR where you have tens of thousands of lines of code changed all it was.
- 19:58So how do you split that up?
- 20:00You know, how do you...
- 20:01I think Sam was looking for a kind of pre-approval before submitting a PEP.
- 20:07I think some people were reluctant to...
- 20:09Right, right.
- 20:09Just taking the temperature of the room to see if it was just...
- 20:13Yeah.
- 20:13If it was welcome or unwelcome, right?
- 20:15I think the general mood was sort of cautious, if that makes sense.
- 20:18Yeah.
- 20:18Like, yes, we'd need to set the plan before we give our stuff.
- 20:23Yeah.
- 20:23That was the kind of vibe I got.
- 20:24Okay.
- 20:24There was some feedback, like from Barry Warsaw and Itamar Osterker about the impact it might have on third-party libraries.
- 20:32I think Carol Willing also talked about that because especially these C layers or these native code layers are super common in the data science space, especially.
- 20:41So, yeah, some conversation about that, right?
- 20:44Yeah, I think there's a lot of concern about with some features new to the language, for example, with typing was added a few releases back.
- 20:53I'm very involved with the typing community.
- 20:55I'm a massive fan of typing.
- 20:57I am too.
- 20:57Fan, not involved.
- 20:58Sure.
- 20:59But, you know, it's kind of got a little bit of a bad name for itself in some ways because there's some people who go to maintainers and demand that typing to be added or whatever.
- 21:11Right.
- 21:11And that's not really felt on the maintainers because everybody's volunteer doing it for free.
- 21:15It is getting easier because one of the holdups used to be, well, my library is for Python 2 and 3 and I'm not going to maintain two versions and so on and so on.
- 21:26Right.
- 21:26So, the typing wouldn't work in Python 2.
- 21:29At least now we're generally past that holdup.
- 21:32But still, yeah, it's effort that the person might not want to put out there.
- 21:36I'm a TypeShed maintainer.
- 21:37Yeah.
- 21:38I'm very involved in typing.
- 21:39So, yeah.
- 21:39Tell people about TypeShed.
- 21:40TypeShed's pretty cool.
- 21:41Oh, sure.
- 21:42So, TypeShed is the repository of stubs for the standard library and also a bunch of third-party stubs.
- 21:50So, TypeShed is like the only version of the standard library that mypy knows or Pyright or PyType or any other type checker.
- 21:59They don't actually know what's going on in real standard library at all.
- 22:04They only know this bundle of stubs and TypeShed.
- 22:08They don't feel like I'm explaining it very well.
- 22:09Yeah.
- 22:09So, you know, I'll pull it to one for app pairs.
- 22:10And people, these are not PY files.
- 22:13These are PYI files.
- 22:15Yes.
- 22:16And if you look at them, the implementation is super straight.
- 22:19Information?
- 22:21I don't know.
- 22:22The implementation of all these is super interesting because all the functions are dot, dot, dot.
- 22:27And the default values are dot, dot, dot.
- 22:29But what you have is you have function name, variable name, type, return value, type, or class, field type, field type, field type, field type, right?
- 22:40Yeah.
- 22:40So, it's like a Python file would like...
- 22:43Yeah.
- 22:43I suspect some people don't even know that this is a thing you can do to improve the understanding of editors and stuff, right?
- 22:49In mypy.
- 22:49A static type checker will use this information to inform the, like, the errors that's flagging on your file if you use it to check a file.
- 22:57So, if you import appders in your Python project and you install types appders, then mypy will use the type in some type check to understand, ah, okay, this app does instance has an app name.
- 23:10Oh, interesting.
- 23:11To add the address of type checker.
- 23:13Do you know what the editors do?
- 23:14Like, does PyCharm already have this information?
- 23:17Does VS Code already have this information from other sources or behind the scenes?
- 23:22So, PyCharm...
- 23:22VS Code does use type checker completely.
- 23:26PyCharm, I think, mostly uses type checker now.
- 23:29It was kind of...
- 23:30They used to have their own way.
- 23:31Yeah.
- 23:32I think it was a bit of a journey for them to move to type checker.
- 23:35I'm not sure if they 100% do yet, but yeah.
- 23:39Okay.
- 23:39Yeah, very interesting.
- 23:40Let's see.
- 23:40We were talking about the CPython stuff and Mr. Hypermagnetic asked, will CPython ever become Rust Python?
- 23:47They also pointed out that type, hence, saves lives.
- 23:50Saves lives.
- 23:51It's great.
- 23:51But back to the first question.
- 23:53Did that come up?
- 23:54Did Rust ever come up?
- 23:56My first thought is that's a pretty far bridge, but did it come up?
- 23:59There is already Rust Python, I think.
- 24:01You can go and use that if you want.
- 24:03Sure.
- 24:04I think it's quite a long way from becoming the default, like default, you know, from becoming the leading version of the reference implementation of Python.
- 24:11Yeah.
- 24:12Okay.
- 24:12We can come back to that in a little bit because it'll circle its way back a little bit.
- 24:16Yeah.
- 24:16All right.
- 24:17We're halfway through the show and we've got one of our items done.
- 24:20Fantastic.
- 24:20Yes.
- 24:20Let's go to the next one.
- 24:21No, we'll pick up speed as we go.
- 24:23Yeah.
- 24:23This next one is a per interpreter gill, which actually has been a little bit around from PEP 684.
- 24:32And it's still in draft mode from Eric Snow.
- 24:35And so this also goes back to dealing with the GIL.
- 24:38And it tries to, instead of remove it, say, well, you know what the GIL does is it makes you have single threaded code.
- 24:44So what we're going to do is if you want to run a thread, you just start a new sub interpreter in the same process.
- 24:51And sure, it has a gill, but it's meaningless because there's only one thread per interpreter.
- 24:57And so it's a way to kind of sidestep that problem, right?
- 25:00Yeah.
- 25:01It's kind of funny.
- 25:01So the first talk is like, yeah, let's get rid of the GIL.
- 25:04And then Eric comes along and says, but what if we had lots of gill?
- 25:08The problem is the GIL is shared.
- 25:09Yeah.
- 25:10Although we got to rename it if there's a per interpreter GIL.
- 25:13Yeah.
- 25:14It's not globally, right?
- 25:15It should just be a per interpreter ill.
- 25:17The gill, the g part, the global doesn't make sense anymore.
- 25:20A pill?
- 25:21Yeah.
- 25:22A pill?
- 25:23Yeah.
- 25:23That sounds a little bad.
- 25:24But it's interesting to point out, you know, like you pointed out in your article here, that back in 1997, you know, posted something saying, massive changes for separate thread state management.
- 25:36All per thread globals are moved to a struct, which is manipulated separately, you know, basically trying to do the same thing.
- 25:44And it turns out, though, that through another picture that you've got laid out here, there's actually a lot of global state shared across threads and different things, right?
- 25:55That's the problem.
- 25:55I think if I understand it correctly.
- 25:57So, I mean, I'm angry mouth.
- 25:59It's wrong.
- 26:00I have had him on the show before, so I'll link to that episode as well.
- 26:03I think it is possible now to run multiple interpreters within the same process.
- 26:09But it just doesn't work very well, if I understand correctly.
- 26:11So, it's like, you know, running to all sorts of problems, which, web safety, and, yeah, various conditions.
- 26:17Okay.
- 26:18There we go.
- 26:18Interesting.
- 26:19Yeah, so it sounds like he's been working on this for a long time.
- 26:22I think you opened with a funny quote.
- 26:25Hopefully, the speaker began.
- 26:27This is the last time I give a talk on this subject.
- 26:30He's been working on it since 2014.
- 26:32Yeah.
- 26:33I think at the time he gave the talk, he was hoping to get it in for 3.11.
- 26:38But didn't quite make it.
- 26:39Yeah, exactly.
- 26:40So, maybe it'll be 3.12.
- 26:42Yeah, because 3.11 is already frozen.
- 26:44Yeah, and it's still in draft mode.
- 26:45Okay.
- 26:46So, that's a good one.
- 26:47People can check that out.
- 26:49There's a tension between many of these projects in that the optimizations one are making might be complicating the work the others are doing.
- 26:57Yeah.
- 26:58And that's also true for the next one here, which actually, I think, is the biggest news of Python 3.11.
- 27:03I completely agree.
- 27:04Performance improvements.
- 27:05Yeah.
- 27:06Performance improvements for 3.11.
- 27:07I feel like it's a shame that so many more people read the no-kill one than this one, actually, in a way.
- 27:13Yeah.
- 27:13But, you know, I've been watching a C-Python repo.
- 27:15I know how much work has been going into this.
- 27:17And I think it's really impressive.
- 27:20Yeah.
- 27:20Yeah.
- 27:20So, essentially, the top-line news from this is Python 3.11 is going to be about 25% faster than Python 3.10.
- 27:29And this is mainly a result of implementing a PEP by Mark Shannon.
- 27:35Not sure I can remember the number of the PEP.
- 27:37It's known as the Shannon plan.
- 27:39Yeah.
- 27:40I'm making Python five times faster over five years or something like that by doing, like, this 1.25x per year, which they did it this year.
- 27:48That's incredible.
- 27:48The main chunk of this is that there are loads of, like, small optimizations that have gone into this.
- 27:53But a lot of them have to do with implementing what's called a specializing adaptive interpreter.
- 27:58Okay.
- 27:58What does that mean?
- 28:00What is that?
- 28:00So, this is essentially an interpreter that monitors your program as it's running and spots if you've got, like, an inefficient bytecode that can do lots of different things.
- 28:14So, like, maybe it's an add bytecode that could plausibly, I'm almost settling in and get some details wrong here.
- 28:21But, you know, maybe it could add two lists together or add two ins together.
- 28:25You know, it's just like a generic add bytecode.
- 28:28And then the specializing adaptive interpreter will spot, oh, hang on.
- 28:33Okay, we're in a tight loop here.
- 28:34Only numbers are being, only ins are being added here.
- 28:37We can replace this bytecode with a more specialized one, which will do the same thing faster.
- 28:42Yeah, because there's probably a lot of checks and different types of bits of indirection to let it add strings and lists and so on.
- 28:49But if you know it's numbers, then just do the number thing without the checks.
- 28:51Exactly.
- 28:52So, that's known as quickening.
- 28:53So, like, as the program's running, specializing adaptive interpreter quickens your code and replaces the bytecode with a more specialized one.
- 29:02This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 29:09Starting a business is hard.
- 29:11By some estimates, over 90% of startups will go out of business in just their first year.
- 29:16With that in mind, Microsoft for Startups set out to understand what startups need to be successful and to create a digital platform to help them overcome those challenges.
- 29:25Microsoft for Startups Founders Hub was born.
- 29:28Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
- 29:35The platform provides technology benefits, access to expert guidance and skilled resources, mentorship and networking connections, and much more.
- 29:43Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be investor-backed or third-party validated to participate.
- 29:53Founders Hub is truly open to all.
- 29:56So, what do you get if you join them?
- 29:57You speed up your development with free access to GitHub and Microsoft Cloud computing resources and the ability to unlock more credits over time.
- 30:05To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI, a global leader in AI research and development, to provide exclusive benefits and discounts.
- 30:15Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
- 30:20You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation, fundraising, management and coaching, sales and marketing, as well as specific technical stress points.
- 30:34You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
- 30:39Make your idea a reality today with the critical support you'll get from Founders Hub.
- 30:44To join the program, just visit talkpython.fm/founders hub, all one word, no links in your show notes.
- 30:50Thank you to Microsoft for supporting the show.
- 30:52Have you heard of Brandt Bucher's specialist project?
- 30:59No.
- 30:59So, if you look that up on GitHub, it's a project that he published a few weeks ago, I think, and it's really cool.
- 31:06You can see, it's like visualizes the way Python 3.11 will quicken your code that it's running.
- 31:13So, I'll send you a pass and link.
- 31:15Yeah, yeah.
- 31:16Send your link.
- 31:16Yeah.
- 31:17Tomer points out that they've been following the faster CPython repository.
- 31:22And yeah, I'll link to that as well.
- 31:24You know, Mark Shannon and other stuff.
- 31:26The ideas for making CPython faster over time and different things.
- 31:30Yeah.
- 31:31So, yeah.
- 31:32Very cool.
- 31:32Yeah.
- 31:32So, that does like the ideas hub with all.
- 31:35Visualizing.
- 31:35It's specializing adaptive interpreter.
- 31:38Okay.
- 31:38Yeah.
- 31:39All right.
- 31:39Very interesting.
- 31:40So, this is the thing.
- 31:42Pip install specialist is a thing you can do.
- 31:44And then it'll what?
- 31:45It'll show you like a printout of the code where it's actually found improvements?
- 31:50Exactly.
- 31:50So, it'll show you where it's quickened your code and where it's been unable to quicken
- 31:55your code.
- 31:55So, I think the green bits here, specialist has, yeah, quickened those bits of code.
- 32:01But the other bits, it's been like, yeah, don't know what to do here.
- 32:04Got to leave it.
- 32:05I said it.
- 32:05Couldn't do anything.
- 32:06Yeah.
- 32:06Yeah.
- 32:06So, for people listening, if you just pull up the specialist GitHub repository, which
- 32:10I will put in the show notes, there's a bunch of pictures and colorized code showing you
- 32:15where Python 3.11 was able to make it faster and where it wasn't.
- 32:18This is super cool.
- 32:19I never heard of this.
- 32:21Yeah.
- 32:21And this is a project by Brant Booker, who's been one of the major collaborators on the
- 32:28FasterCPython project.
- 32:29Right.
- 32:29Coming from the top.
- 32:30Yeah.
- 32:30What also is neat is this is not just for 3.11.
- 32:333.11 is the first step.
- 32:35They're like only halfway through.
- 32:36Yeah.
- 32:363.12 is currently.
- 32:37It's pretty well funded, too, right?
- 32:39Like, Microsoft has, I think, a team of six people possibly working with Guido and Mark.
- 32:44Sounds about right.
- 32:45And then also Bloomberg has contributed some resources or some help.
- 32:50Yeah.
- 32:51Yeah.
- 32:51It's really got a lot of speed here.
- 32:52A lot of inertia behind it, I guess I should say.
- 32:55And speed.
- 32:55Absolutely.
- 32:56All right.
- 32:56This one, actually, I think this is the big news.
- 32:59I know that it probably didn't make the biggest splash of the headlines, but.
- 33:03I think it's going to, yeah, because this is going to make everybody's code
- 33:05faster.
- 33:06It's not like one small micro-optimization.
- 33:09It's across the board.
- 33:10Right.
- 33:11Yeah.
- 33:11The threading stuff is very exciting and interesting, but I'm going to go out on LM and say, I think
- 33:16a lot of people think they need it or they think they want it more than they actually
- 33:20need it.
- 33:21So, for example, if you're running a website with APIs and stuff, you know, Gunicorn or
- 33:28Microwave's Geek or whatever, they all spin out a bunch of worker processes and you can
- 33:32have several worker processes per core, meaning you're already like saturating every core of
- 33:37the CPU.
- 33:39You know, so in those scenarios, it's nice, but it doesn't help that much in terms of, you know,
- 33:43a lot of stuff that you don't really need the threading.
- 33:45On the data science side, you might, but at the same time, you often, you're doing the computation
- 33:50in C or you can use async and await if it's IO bound.
- 33:53There's a lot of ways where this problem is actually already solved.
- 33:55It just doesn't feel like it's solved.
- 33:57And so this one though, this fix it, this makes multi-threaded code faster, single-threaded
- 34:02code faster.
- 34:03It's just, it just makes all the code faster, which is great.
- 34:05This could be a given at a run for the money.
- 34:07You know, when the listener asked earlier about Rust being the reference implementation
- 34:13for CPython, well, what is it then?
- 34:15RPython?
- 34:16I don't know.
- 34:16Maybe CPython isn't the name for it anymore.
- 34:18The reference implementation for Python.
- 34:20This one here, Python in the browser, could put some pressure to move in that direction.
- 34:25Right?
- 34:25So this one has to do with WebAssembly.
- 34:27Tell us about this.
- 34:28For a while now, there's been a project called Pyodide, which has been like a third party project,
- 34:33which has been monkey patching, essentially, CPython to get a version of CPython running in
- 34:39the browser.
- 34:39Pyodide has been the basis for several cool projects, which are all sort of just starting to take off
- 34:47now.
- 34:47I feel like we've sort of reached this like critical point where it's all the finest of
- 34:52starting to fit together and make sense.
- 34:54And over the last two years, Christian Himes, co-developer and contributor Ethan Smith have
- 35:01been working to upstream loads of these changes that Pyodide has been making to CPython itself,
- 35:08which would mean that Pyodide doesn't need to monkey patch CPython nearly so much anymore.
- 35:14And so I think that's actually will just work in the browser, which would be huge.
- 35:18Yeah, that's fantastic.
- 35:20There were a bunch of changes made to make this possible.
- 35:22And I can't remember where in the article you said, but yeah, over 60 PRs.
- 35:27Yeah.
- 35:28Yeah.
- 35:28And a GitHub issue, right?
- 35:29That's one.
- 35:29We just like see the numbers.
- 35:31Consider supporting mscripten slash WebAssembly as a build target.
- 35:35And guess what?
- 35:36That's not a thing.
- 35:37Now you can actually go in and say --with inscripten target equals browser as to compile
- 35:45CPython.
- 35:45And that's a big deal.
- 35:47I think it's going to make it possible to use Python where you would have otherwise used
- 35:52JavaScript.
- 35:53For sure.
- 35:53So I think this is possibly one of the biggest gripes that anybody using Python for web development
- 35:59has.
- 35:59And then have to like use JavaScript.
- 36:02Yeah, people will say sometimes to me that I'm being mean or inconsiderate or something
- 36:07when I say that we might not want to write in JavaScript.
- 36:10You're like, why are you hating on JavaScript?
- 36:12I think the frustration that a lot of people feel in the software industry is not that they
- 36:17necessarily hate JavaScript, that JavaScript is the only option.
- 36:21Like there's almost nowhere else in programming where we go, there's one language and one runtime
- 36:26and that's it.
- 36:27That's all you get to use, period.
- 36:30Right.
- 36:30On the desktop, on embedded, on the web, like on, you know, server side web, like you
- 36:35can pick tens of languages at least.
- 36:38Right.
- 36:39And you pick the one that works well for you and the one you like.
- 36:41And except for in the browser, everyone is forced to do this one language, which is frustrating.
- 36:46And so as Python developers, where we like Python, it would be great if we could continue to use
- 36:52a language that we prefer for things like this.
- 36:55Right.
- 36:56Yeah.
- 36:56And now you can.
- 36:56And now you can.
- 36:58There's a few challenges with this.
- 37:00One is that the WebAssembly binaries are a bit large, not huge.
- 37:04They're not huge, but they're like five or 10 megs instead of 50k.
- 37:08So that's a bit of a challenge.
- 37:10But there's places where this is already highly valuable.
- 37:13So for example, if you're doing like an Electron JS app, you could write that largely in Python
- 37:19using this stuff already.
- 37:22And it doesn't matter because you already downloaded an entire copy of Chrome.
- 37:25What's another 10 megs?
- 37:27You know, is it 200 or 205?
- 37:29Like, I don't care.
- 37:30It's the same.
- 37:30Yeah.
- 37:31I think Simon and Willison might have done that a few weeks ago.
- 37:34Okay.
- 37:35I created an Electron JS app with PyScript?
- 37:38Yeah, I think so.
- 37:39I'll have to look into that.
- 37:39That sounds really fantastic.
- 37:40Let's see.
- 37:42So this is cool because PyIodide is great, but it's like this sort of project maintain
- 37:48alongside CPython.
- 37:49And this is saying the core developers and the team behind Python are allowing you to just
- 37:55compile a limited version directly, right?
- 37:58So PyIodide could say build on top of this one and not have to maintain their own copy.
- 38:03Exactly.
- 38:03Yeah.
- 38:03So we do need to be careful here.
- 38:05Like, it's mscripts in the WebAssembly are not fully supported by CPython yet.
- 38:10There was a lot of concern about that at the summit.
- 38:11Like, if we say it's supported now, then it's a big statement to put out there.
- 38:17So definitely not fully supported yet.
- 38:19Yeah.
- 38:19Okay.
- 38:19Good to point that out.
- 38:20And there's plenty of things that are not supported because they're probably not just
- 38:25haven't, they're not ready.
- 38:26Some things that will never, ever be supported.
- 38:29Like TK Enter support is probably never coming to the browser.
- 38:32Yeah.
- 38:33You know what I mean?
- 38:34Or other things that are not permitted by the browser's sandboxing rules and so on.
- 38:39Anything that can be run in the browser needs to be extremely security conscious because
- 38:44nobody expects to have arbitrary code execution on the browser.
- 38:47It sounds very, very suspicious.
- 38:49Like, you're going to let me run binary code in the browser, but it's subjected to exactly
- 38:53the same rules as JavaScript.
- 38:55And JavaScript gets JIT compiled to binary code and then run anyway.
- 38:58It just feels better that it's like, oh, here's a script.
- 39:00It's like, no, it's the same thing.
- 39:02So very cool.
- 39:03I do want to just point out, give a quick shout out to PyScript, which you also did in
- 39:07your article.
- 39:08This is super exciting.
- 39:09This takes it and makes it way, way more real.
- 39:11This is where you really do put Python in the browser.
- 39:14This is built on top of Pyroidite, I think.
- 39:16Yep.
- 39:17Just enables you to embed Python inside an HTML file.
- 39:22And it just works.
- 39:23Yes.
- 39:24Yeah, it works pretty well.
- 39:25Opening tag, py-script inside an HTML file.
- 39:29And don't need to download anything.
- 39:31Yeah.
- 39:32Pretty incredible.
- 39:32You can also say source equals app.py in your browser.
- 39:37And as long as that can be delivered as a static file, it'll pull that up and run.
- 39:41I just, quick follow up on this.
- 39:43No, this is a different one.
- 39:44I'll roll it.
- 39:46But I do want to point out that I actually, I don't know if people know this.
- 39:49I did a video called Python PyScript WebAssembly.
- 39:51And then I actually created an offline progressive web app with it.
- 39:55So once you've installed this app, it no longer has to download that larger binary.
- 40:02So if you look at the code, it's like super, super simple.
- 40:05You can get this cool little offline app.
- 40:07And it is like launch time, you know, down to one second, maybe one and a half seconds.
- 40:13And it's just so bizarre to write Python for like JavaScript events.
- 40:18So you can say like on click equals here's the Python function and all sorts of stuff.
- 40:23So people can check that out.
- 40:24I'll link that in the show notes.
- 40:25This is a really big deal.
- 40:27This WebAssembly stuff that's coming in.
- 40:29It's coming from these different angles.
- 40:30It's coming from Pyodide, from PyScript, from the core developers compiling to WebAssembly.
- 40:35All of those things are pretty fantastic.
- 40:38It's really cool to see so many people collaborate on the same thing at once.
- 40:41From seven different parts of the community.
- 40:43It's true.
- 40:43It's happening.
- 40:44There's two parts where that's happening, right?
- 40:45In this GIL thing and in the WebAssembly side of things, right?
- 40:49They're not necessarily coordinating, but they're all working on the same problem.
- 40:53And surely we'll get some good outcomes from that.
- 40:55All right.
- 40:56Let's talk about the Cinder one next.
- 41:00So this one does come also from Meta and more Instagram, I suppose, directly.
- 41:04But this comes from the Cinder project.
- 41:07And this has to do with some of the optimizations.
- 41:09You want to tell us about this one?
- 41:11These are essentially async specific optimizations.
- 41:14So Cinder, for those who don't know, is a performance-oriented fork of CPython.
- 41:20So the Instagram team essentially were like, we really love Python, but it's a bit too slow for our web servers if we're going to have the whole thing written in Python.
- 41:28So they forked it and implemented.
- 41:30There's a ton of different optimizations implemented in Cinder.
- 41:35Many changes.
- 41:35Yeah.
- 41:36There's a ton.
- 41:37If you check out the Cinder project, there's just a whole list of all these different things.
- 41:41Some of them have to do with JIT.
- 41:43Some of them have to do with immortal objects and some have to do with other things as well.
- 41:49Yeah.
- 41:49Async IO.
- 41:50Lazy imports.
- 41:51Yeah.
- 41:51Loads of stuff going on.
- 41:53Yeah.
- 41:53With all the attention recently on making Python faster, the Cinder team is hopeful that they will be able to get some of their optimizations merged into the main drive to Cpython.
- 42:04So this presentation was specifically about some of the async specific optimizations that they have been implementing in their fork.
- 42:12So essentially, the issue is to do with eagerly awaited coroutines.
- 42:19So if you have coroutine, then generally, if you have a coroutine function, you'll call that function.
- 42:26It will create this coroutine object.
- 42:27That coroutine object doesn't do much until you await it.
- 42:31And then eventually you get the result back.
- 42:33But that can be inefficient in some situations.
- 42:37Because if the task being done in the coroutine can just sort of finish immediately, then there's no reason to create that coroutine object.
- 42:46Right.
- 42:46And to schedule it and to do all the stuff on the loop and then wait for it.
- 42:50All of that is just overhead.
- 42:53What's done in the Cinder fork is they detect when a task can be immediately finished and don't bother correcting the coroutine object in that case.
- 43:03So let me see if I can come up with an example for people that might make it concrete.
- 43:07Kind of complicated.
- 43:07Yeah, no, it is.
- 43:08But I think once you get this feel for it, it's no problem.
- 43:11It's not that bad.
- 43:12Probably bad to implement, but not bad to understand.
- 43:15So imagine you have an async function that's going to call an API, but you might have an in-memory cache that says, have I already looked this up for this particular argument?
- 43:25Right.
- 43:25So your code could say, if this value is in the cache, just return that value.
- 43:30Otherwise, await HTTPX get da-da-da-da-da.
- 43:33Right.
- 43:34So that first case where you call something that's in the cache, by default in Python now, it's going to still schedule that on the loop and it's going to make it run on the loop and wait for all that to happen in this inefficient way.
- 43:46So the optimization is like run it as a regular function until you hit an await and then go through that process.
- 43:53Something like that, right?
- 43:54I think so.
- 43:55That's my understanding.
- 43:56And people can send me messages and let me know I got it wrong.
- 43:59But I think that's the basic idea.
- 44:00There's scenarios where, in my case, if it's in the cache, it doesn't ever really need to be treated as a async coroutine ever.
- 44:08You just get the value back like a regular function.
- 44:10But if it goes past that, then it does need to be one.
- 44:12And that's the distinction, I think.
- 44:14Okay, cool.
- 44:15So there's actually a lot of improvements and performance things coming from the Cinder project.
- 44:19There's this one, but there was also the lazy imports, right?
- 44:23PEP 690 and that one and so on.
- 44:25On discuss.python.org, there's been a, I think a discussion has reached to over 100 comments now on lazy imports.
- 44:32So if you have views, that is where to send them.
- 44:37Absolutely.
- 44:37That's a whole different proposal where you could, we should introduce an API to enable or disable lazy imports.
- 44:45So with lazy imports enabled.
- 44:47So at the moment, all imports in Python are eager.
- 44:50So if you type in import functools at the top of a file, it will execute the entire functools module and then put a reference to that module in your file for you.
- 45:01Whereas with lazy imports enabled, it would see the import functools statement.
- 45:05It'd be like, meh, not going to do anything with that.
- 45:07And then wouldn't actually import the module until the first time functools was referenced later on down the file.
- 45:13Right.
- 45:13Because the problem is there's a cost for doing an import.
- 45:16It's not like a hash include, which might be a compile time thing.
- 45:20There's an actual runtime cost for every import.
- 45:23So PEP 8 says all the imports go at the top to keep them orderly.
- 45:27But if there's many apps that might or might not use some import, depending on what part of it runs.
- 45:34Right.
- 45:35Yeah.
- 45:35And so if you could delay that, that expense only if you use it, that would be great.
- 45:40And this can have a major impact on startup time for Python CLI apps.
- 45:44Yeah.
- 45:44Especially.
- 45:45Yeah.
- 45:45Yeah.
- 45:45The one that we were talking about is this ASIC optimization.
- 45:48So that's the one that was actually covered, but it's just one of the things coming out of Cinder, which is cool.
- 45:54Yes.
- 45:54And then I think maybe this path forward for immortal objects.
- 45:59Is that also coming out of Cinder?
- 46:00Sounds like it.
- 46:01No, that's another one.
- 46:03Similar, but not the same.
- 46:04This is linked to the current up to Gil talk, essentially.
- 46:10Okay.
- 46:11This is one of those proposals that's kind of very much in the weeds of how Python is implemented.
- 46:17So it's a proposal to introduce what's known as immortal objects.
- 46:22So an immortal object is, well, an object that never dies.
- 46:26So generally in Python, as we were talking about earlier, objects have a reference count.
- 46:31And if that reference count reaches zero, then the garbage collector comes along eventually
- 46:36and deletes it, freeing out memory that was holding that object.
- 46:40So this path proposes introducing a class of objects where the reference count would never
- 46:45reach zero, meaning that the object would never be cleaned up by the garbage collector and would
- 46:51never die.
- 46:51So this would have the advantage.
- 46:53Yeah.
- 46:53Because why are you bothering to like check and check on these objects that you know will
- 46:58never, ever have any sort of reason to go away?
- 47:01Right.
- 47:02So like there's the non-singleton, for example, like it would be quite rare to have a program
- 47:06that doesn't use none at least once.
- 47:08Or the number five, which is pre-allocated, right?
- 47:11As well as the number 200, like the first, the last, the first negative five in the top 255
- 47:18or something like that.
- 47:19Yeah.
- 47:19But nonetheless, Python will like doggedly keep a reference count for these objects and
- 47:25like track where they are.
- 47:27Yeah.
- 47:28So for a lot of these, yeah, pre-allocated object numbers, in terms strings, the empty
- 47:35tuple, I think is also singleton, the non-singleton.
- 47:39These would all become immortal objects if this path accepted.
- 47:43And that would, I think in the short term, make Python a little bit slower, probably.
- 47:48So I think a naive implementation makes it slower by around 6%.
- 47:52But with mitigations, you can make it so that performance impacted is marginal.
- 47:58But then if you do implement immortal objects, there's, it makes things like a paratexta
- 48:04gill easier.
- 48:05It might also simplify no gill, I think.
- 48:07Yeah, probably.
- 48:08Because once you know something's immortal and probably also immutable, then you can share
- 48:14it all you want.
- 48:14Yeah.
- 48:15Exactly.
- 48:15Yeah.
- 48:16So you don't have to worry about.
- 48:17Yeah.
- 48:17Yeah.
- 48:17So some of that state that's really hard to create one per interpreter, you're just like,
- 48:21well, it doesn't change.
- 48:22So here it is.
- 48:23Yeah.
- 48:24You don't have to check it either.
- 48:24Yeah.
- 48:25Cool.
- 48:25It just kind of makes sense when you think about it in a way, I think.
- 48:29You know, like, why would you track the reference counts for all of these objects?
- 48:32Exactly.
- 48:33You know, like, true and false are never going to be gone.
- 48:35So just forget it.
- 48:36Just leak that memory or whatever, right?
- 48:39Yeah.
- 48:39Yeah.
- 48:40All right.
- 48:40Let's see.
- 48:40What else we got to cover here?
- 48:42Maybe the issues and PR backlog?
- 48:44Sure.
- 48:45It's one of the, I think that's the longest one.
- 48:47Okay.
- 48:47Yeah.
- 48:47This is a pretty interesting aspect because it has to do with the developer in residence
- 48:52and Lucas Lange and all the improvements that having somebody dedicated to that role has
- 48:57brought, right?
- 48:58There are a lot of open issues and open PRs on CPython.
- 49:01But this talk was actually kind of taking a step back and looking philosophically about
- 49:07it and sort of saying, well, what is an issue for?
- 49:10You know, why there's all these issues.
- 49:13Some of them haven't had activity on them for five years or whatever.
- 49:17Like, why is that issue still open?
- 49:19Like, what is that doing for us really?
- 49:21And also, I guess, really quick shout out.
- 49:23This is from Edreet Catrail.
- 49:25Yes.
- 49:25This talk.
- 49:26So I think it's like two perspectives, right?
- 49:29You see the person who, when they open their phone at the bottom, it has 26,214 unread messages.
- 49:36The first is inbox zero.
- 49:38Like, you know, it's like, well, if we can't close this issue and we can't deal with it within
- 49:44five years, it's just friction.
- 49:46That's one side of the argument, I suspect, is it's friction.
- 49:50The other people are like, well, this is history.
- 49:51Yeah.
- 49:51Historical friction.
- 49:52What do we do about it?
- 49:53Sahih Spachaka, one of the most prolific SuperIcon core developers who's contributed more to
- 49:59SuperIcon, like I'd say.
- 50:00You're sort of saying, well, you know, sometimes I do come back to issues after five years.
- 50:05I do.
- 50:06I am planning on working on it, but I'm working on a lot of things and have hundreds of local
- 50:11branches and I'm working on loads of things at once.
- 50:14And sometimes I forget about something for five years and then come back to it, which is
- 50:17totally fair.
- 50:18It is fair.
- 50:19But I don't think like one person isn't going to fix all of those issues.
- 50:23You know, when you've got, how many is it now?
- 50:26See, six, over 6,500 open issues on the CPython repo.
- 50:30Yeah.
- 50:30Yeah.
- 50:31I don't know how I actually fall on this.
- 50:33I mean, on one hand, I totally get that you want to keep it around.
- 50:37On the other, if it was something really important, it would probably resurface again anyway.
- 50:42You know what I mean?
- 50:43Like...
- 50:44No, I completely get that.
- 50:44I think at the moment, my personal opinion is we do have too many open issues at the moment.
- 50:49And a lot of them just aren't ever going to have...
- 50:52Either aren't going to get fixed or like, if they are going to get fixed, it's not because
- 50:55of the issue being open.
- 50:56Like somebody else will just come along and be like, I'm going to fix this now.
- 51:00It's on GitHub now.
- 51:01You could apply a tag to it like closed due to old age or something.
- 51:05Yeah.
- 51:06And then just close them.
- 51:06They can be reopened.
- 51:08People could go, well, I really want to see all the ones that were closed due to old age,
- 51:11plus the ones that are open.
- 51:12You know, just create a search that shows that view.
- 51:16Somebody's really bored and is like, I really want to fix some Tkintered feature requests
- 51:2120 years ago.
- 51:22We can scroll through those.
- 51:25Yeah.
- 51:27Yeah, for sure.
- 51:28Okay.
- 51:29It's an interesting conversation and discussion and what to think about, but it's not something
- 51:33that directly affects people.
- 51:35Like that's the perfect kind of thing that's like handled at this meeting, right?
- 51:39Because it's really about those folks.
- 51:40Yeah.
- 51:40Yeah.
- 51:41All right.
- 51:41The final one, the F string grammar.
- 51:43We got f-strings in Python 3.6 and it's one of the most popular languages added recently,
- 51:48language features.
- 51:49Everyone loves it.
- 51:51I've heard people upgrading to 3.6 and beyond or throwing away old versions just so they can
- 51:55write f-strings, which is great.
- 51:57But it turns out that the actual parser for f-strings is kind of insane.
- 52:01I had no idea.
- 52:02Tell us about that.
- 52:03I think it was how many lines of code is it?
- 52:05I think it wrote it in the article.
- 52:061,400 lines of custom C parser code just for f-strings that's separate from the regular parser.
- 52:14This whole file is just manually handwritten C code to parse f-strings.
- 52:19And Pablo brought up this crazy slide on that.
- 52:22This talk is by Pablo.
- 52:24And the Salgado.
- 52:25He is a core developer, steering council member, and lead manager for Python 3.10 and 3.11.
- 52:32So this is his big project.
- 52:35So yeah, Pablo brought up this crazy slide showing the dance that the interpreter has to go to
- 52:42whenever it encounters an F string.
- 52:44It's like a passed.
- 52:46It sounds really tricky to figure out because you've got all the captured variables.
- 52:50You've got to figure out how to pass those over.
- 52:52Then it goes to the parser and it's like, oh, geez.
- 52:54Okay.
- 52:54Yeah.
- 52:55So what is the idea?
- 52:56The idea is to make this part of the regular parser?
- 52:58Just move this over to bring it into the peg parser and all those kinds of things.
- 53:02Okay.
- 53:03Yeah.
- 53:03So since Python 3.9, Python has had a generated parser.
- 53:08So you just write all the grammar rules down in this file according to a mini language for
- 53:16the grammar.
- 53:16And then the program will generate a very large C file to parsing Python according to those
- 53:23rules.
- 53:23So it's a much nicer way of doing things.
- 53:26It's much less error prone.
- 53:28Just generate all the C code instead of writing it all out.
- 53:32And so Pablo's big idea is, yeah, let's just move all this F string parsing into the grammar.
- 53:37Do it all at the same time as that.
- 53:39Be much cleaner.
- 53:41It's nicer to maintain.
- 53:43And it also has some exciting things for users.
- 53:48It will mean that the code team will be able to do some big work on improving error messages,
- 53:53for example, for f-strings.
- 53:55It's currently quite hard to do because if you touch one corner of this C file, it could have
- 54:01a chain reaction to the rest of it and cause you 10 bugs and nobody wants that.
- 54:04Yeah, that's great.
- 54:05That's one of the other areas of focus there has been lately on improving error messages.
- 54:09That's good.
- 54:10Yeah.
- 54:11310 had improvements just in general for error messages.
- 54:14Yeah.
- 54:14Maybe that also comes from the peg parser, right?
- 54:16Like maybe that's related.
- 54:17If like the peg parser already has better error messages and you can get this into the peg parser,
- 54:21it'll just bring along better error messages more easily.
- 54:24So the peg parser is smarter than the old parser has.
- 54:26So like the old parser couldn't like look back when it encountered the syntax error, essentially.
- 54:32So like if it encountered the syntax error, it would just kind of throw up its hands and die on you.
- 54:37Whereas the new parser is able to catch the syntax error and then kind of look around context
- 54:43and then give you a better message using that context, essentially.
- 54:47That's great.
- 54:48Yeah.
- 54:48Yeah, yeah, sure.
- 54:48I think that pretty much covers it.
- 54:50Anything else you want to mention to people about the Language Summit?
- 54:54You wrote it up pretty well, I think, but there's something else not in there.
- 54:57Pythons.blogspot.com.
- 54:59It's the address if you want to read that.
- 55:02Yeah, for sure.
- 55:02I'll put the article in the show notes.
- 55:04I think we've pretty much covered everything.
- 55:05We've covered a lot anyway.
- 55:06Yeah, we have covered a lot, Alex.
- 55:08That's great.
- 55:09All right.
- 55:09Well, thanks for all of this and all your work on the other things as well.
- 55:13Before we get out of here, let me ask you the final two questions.
- 55:15If you're going to write some Python code, be it 312 or something new or older,
- 55:20what editor are you using?
- 55:21I'm actually using Idle quite a lot these days.
- 55:24Yeah, right on.
- 55:24I've used Pyjarm for a while.
- 55:26I've tried out VS Code several times.
- 55:27I've never really got on with it.
- 55:29I'm not quite sure why.
- 55:30Yeah.
- 55:30I loved all the features Pyjarm had, but nowadays I'm just enjoying something that just starts
- 55:35up really quickly.
- 55:36And it's just really simple.
- 55:37Something simple.
- 55:38All right, cool.
- 55:39Yeah.
- 55:39And then notable PyPI package or library, something you want to give a shout out to?
- 55:44I mean, we kind of sort of did that in a meta sense with TypeScript or TypeShed, rather.
- 55:48Yeah, am I allowed to shout out my own package?
- 55:51You can shout out whatever you want.
- 55:52Absolutely.
- 55:54I'll just give another shout out to Specialist, I think.
- 55:57I think that's really cool.
- 55:58Yeah, Specialist is neat.
- 56:00I'm glad I learned about that today.
- 56:02That's cool.
- 56:02All right.
- 56:03Well, I can seem magnanimous by shouting out somebody else's project.
- 56:06There you go.
- 56:08All right.
- 56:08Well, thanks for doing the write-up.
- 56:10Thanks for taking good notes and sharing it with everyone.
- 56:12Because while it makes total sense that the Language Summit is this closed-door story where
- 56:19people can have open conversations and just keep it amongst the core developers, I know
- 56:24everyone in the community really appreciates having a sense of what's coming, where the focus
- 56:28is, what people are worried about, and so on.
- 56:30So thanks for getting that out in the light for us.
- 56:33Yeah, no worries.
- 56:34It was fun to do.
- 56:35Yeah.
- 56:35Really fun to have this conversation.
- 56:36Yeah, you bet.
- 56:37Thanks.
- 56:37Awesome.
- 56:38Thanks, man.
- 56:38This has been another episode of Talk Python To Me.
- 56:42Thank you to our sponsors.
- 56:44Be sure to check out what they're offering.
- 56:45It really helps support the show.
- 56:47If you can browse the web, you can create sophisticated tests with Reflect.
- 56:52Navigate to your site within Reflect's simulated browser and perform actions you want to test.
- 56:56Let Reflect handle the painstaking work of test creation and maintenance.
- 57:00Sign up and get a free t-shirt at talkpython.fm/reflect.
- 57:04Starting a business is hard.
- 57:07Microsoft for Startups Founders Hub provides all founders at any stage with free resources
- 57:13and connections to solve startup challenges.
- 57:15Apply for free today at talkpython.fm/foundershub.
- 57:20Want to level up your Python?
- 57:21We have one of the largest catalogs of Python video courses over at Talk Python.
- 57:26Our content ranges from true beginners to deeply advanced topics like memory and async.
- 57:31And best of all, there's not a subscription in sight.
- 57:33Check it out for yourself at training.talkpython.fm.
- 57:37Be sure to subscribe to the show.
- 57:38Open your favorite podcast app and search for Python.
- 57:41We should be right at the top.
- 57:42You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 57:52We're live streaming most of our recordings these days.
- 57:55If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 58:03This is your host, Michael Kennedy.
- 58:05Thanks so much for listening.
- 58:06I really appreciate it.
- 58:07Now get out there and write some Python code.
- 58:09Thank you.
- 58:09衝き心惑
- 58:29Thank you.
- 58:30Thank you.