For the past few years, Microsoft has been contributing to Faster Python, a project kicked off by Python creator Guido van Rossum in 2021, shortly after Microsoft hired him as a distinguished engineer, changing his previous plan to retire.
The Python creator wanted the language to be more nimble than the lumbering giant it is. Van Rossum wanted it to be twice as fast but Mark Shannon, one of the key contributors to CPython (or Core Python), penned an implementation plan in 2020 for speeding up CPython by five times. Core Python is the reference implementation of Python that other variants are based on, like data science-focussed Anaconda.
Python’s popularity can be attributed to the vast ecosystem of packages, like NumPy, and frameworks, like PyTorch, that help number-crunching and data-analysis processes, but those packages, as Microsoft notes, are written mostly in C. Python is an interpreted language versus C and C++, which are compiled languages. As such, CPython relies on C to interpret Python code.
Microsoft hired a team of six engineers along with Van Rossum to deliver the performance improvements via CPython. It’s now detailed how it sees those investments translate into benefits for CPython, whose contributors are mostly volunteers — typically skilled engineers who have other jobs — but now benefit from Mictosoft’s Python hires.
Microsoft showcases the work of staffers Eric Snow, L Pereira, Irit Katriel, Michael Droettboom, and Brandt Bucher, who all helped deliver performance improvements across Python 3.10 and 3.11, which Microsoft claims has seen speedups of between 10% to 60% in some areas of the language.
Snow has been working on sub-interpreters, while Atrial has implemented the new Exception groups and except* features in 3.11. Bucher helped create structural pattern matching.
Microsoft seems cautious to avoid the perception it has an agenda for Python, and is perhaps aware of skepticism among developers due to its past attitude towards Linux and open source.
“How do we make sure we’re showing up to the Python community as helpful, not driving an agenda or any of those kinds of things,” says Droettboom.
“Because what we are doing is kind of risky. There has probably been a higher frequency of unintended consequences and bugs that have come about because we are changing how the core works. It’s really important that the team supports the community to keep quality up.”
Questions still come up about Microsoft’s motivations in open source, but the company has embraced it more purposefully now that Azure and Microsoft 365 and more tightly aligned with the cloud.
Snow apparently spends 20% of his time at Microsoft working on CPython. Katriel says she has been able to focus on performance thanks to Microsoft hiring her and working with Van Rossum.
“Joining the Faster CPython team did change my focus towards performance. In that sense my focus did change, but there was continuity in that I did some work on performance of exceptions. By simplifying the interpreter’s internal representation of raised exceptions, I reduced the time it takes to raise and catch an exception by about 10%. In another project, I made the compiler emit the code of except blocks in a separate area, so that they don’t need to be jumped over in the case that no exception is raised,” she said.
Van Rossum also likes the consistency of working as a team on a regular basis rather than dealing with big changes after the bi-annual conference.
“All six of us meet every Monday,” says Van Rossum. “There’s always more than enough to talk about. That is very different than as a core dev community getting together for a Sprint twice a year, like one day after the conference. That is a very special event, of course, but it doesn’t feed me throughout the year.”
Van Rossum believes that knowledge of one another and their collaborative work gives the team a “leg up” because everyone “knows what communication styles people have and what everybody’s weaknesses and strengths are.”
“As a core (Python dev) team across the whole community, we collaborate pretty well,” says Snow. He’s been a core developer for over a decade and “having a number of core devs working on the same stuff in CPython that are within the company, there’s a little better accessibility…the degree of collaboration is a bit more solid.”