VOOZH about

URL: https://thenewstack.io/meta-adds-cool-new-features-to-python-3-12/

⇱ Meta Adds Cool, New Features to Python 3.12 - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-10-12 06:22:10
Meta Adds Cool, New Features to Python 3.12
Python

Meta Adds Cool, New Features to Python 3.12

Meta adds new features to Python 3.12, which the company uses for its AI/ML efforts.
Oct 12th, 2023 6:22am by Darryl K. Taft
👁 Featued image for: Meta Adds Cool, New Features to Python 3.12
Featured image via Unsplash

Python 3.12 has been released with new features and performance improvements, some contributed by Meta, which is showing its continued support for open source.

“Open source at Meta is an important part of how we work and share our learnings with the community,” wrote Carl Meyer, a software engineer at Meta unit Instagram in a blog post about Meta’s contributions to Python 3.12.

Python is one of the primary programming languages at Meta and is used for its AI/ML work, highlighted by the company’s development of PyTorch, a machine learning framework used for various use cases like computer vision, natural language processing and more. Python is also an essential part of the infrastructure at Meta, as well as the Instagram server stack.

Meta has been working closely with the community to introduce new features and optimizations to improve Python performance and to allow easier third-party experimentation with Python runtime optimizations.

Immortal Objects

One of the new features that Meta added to Python 3.12 is something called Immortal Objects.

Meyer noted that Immortal Objects — Python Enhancement Proposal (PEP) 683 makes it possible to create Python objects that don’t participate in reference counting, and will live until Python interpreter shutdown. The original motivation for this feature was to reduce memory use in the forking Instagram web server workload by reducing copy-on-writes triggered by reference-count updates, he said.

Moreover, Immortal Objects are also an important step towards truly immutable Python objects that can be shared between Python interpreters with no need for locking, for example, via the global interpreter lock (GIL) This can enable improved Python single-process parallelism, whether via multiple sub-interpreters or GIL-free multithreading, Meyer added.

Instagram introduced Immortal Objects — PEP-683 — to Python.

“Now, objects can bypass reference count checks and live throughout the entire execution of the runtime, unlocking exciting avenues for true parallelism,” wrote Eddie Elizondo, another Instagram software engineer in a separate blog post about Immortal Objects. “At Meta, we use Python (Django) for our frontend server within Instagram. To handle parallelism, we rely on a multiprocess architecture along with asyncio for per-process concurrency. However, our scale — both in terms of business logic and the volume of handled requests — can cause an increase in memory pressure, leading to efficiency bottlenecks.”

The problem of state mutation of shared objects is at the heart of how the Python runtime works, Elizondo said. Given that it relies on reference counting and cycle detection, the runtime requires modifying the core memory structure of the object, which is one of the reasons the language requires a global interpreter lock (GIL).

“To get around this issue, we introduced Immortal Objects — PEP-683,” he wrote. “This creates an immortal object (an object for which the core object state will never change) by marking a special value in the object’s reference count field. It allows the runtime to know when it can and can’t mutate both the reference count fields and GC header.”

Other New Features

Other new features Meta contributed to Python 3.12 include:

  • Type system improvements
  • Performance optimizations
  • New benchmarks
  • Cinder hooks

Regarding type system improvements, The engineering team behind Pyre, an open source Python type-checker, authored and implemented PEP 698 to add a @typing.override decorator, which helps avoid bugs when refactoring class inheritance hierarchies that use method overriding.

“Python developers can apply this new decorator to a subclass method that overrides a method from a base class,” Meyer said. “As a result, static type checkers will be able to warn developers if the base class is modified such that the overridden method no longer exists.”

Performance Optimizations

Meyer explained that in previous Python versions, all comprehensions were compiled as nested functions, and every execution of a comprehension allocated and destroyed a single-use Python function object.

However, “We landed PEP 709 for Python 3.12, which inlines all list, dict, and set comprehensions for better performance — up to two times better in the best case,” he said. “The implementation and debugging of PEP 709 also uncovered a pre-existing bytecode compiler bug that could result in silently wrong code execution in Python 3.11, which we fixed.”

Meanwhile, for several years, Meta shared its work on Python and CPython through its open source Python runtime, Cinder. The company has also been working closely with the Python community to introduce new features and optimizations to improve Python’s performance and to allow third parties to experiment with Python runtime optimization more easily, Meyer said.

In addition, he said some parts of Cinder (our JIT compiler and Static Python) wouldn’t make sense as part of upstream CPython (because of limited platform support, C versus C++, semantic changes, and just the size of the code), so our goal is to package these as an independent extension module, CinderX.

This requires a number of new hooks in the core runtime, Meyer noted adding that Meta landed many of these hooks in Python 3.12:

Benchmarks

The Python Performance Benchmark suite is the standard set of benchmarks used in open source Python optimization work. During the 3.12 development cycle, we contributed several new benchmarks to it so that it more accurately represents the workload characteristics we see at Meta.

The company added:

“Meta’s work with the Python community doesn’t end with the 3.12 release,” Meyer said. “We are currently discussing a new proposal, PEP 703, with the Python Steering Council to remove the GIL and allow Python to run in multiple threads in parallel. This update could greatly help anyone using Python in a multi-threaded environment.”

Finally, Meta’s involvement with the Python community also goes beyond code. In 2023, we continued supporting the Developer in Residence program for Python and sponsored events like PyCon US, Meyer said.

TRENDING STORIES
Darryl K. Taft covers DevOps, software development tools and developer-related issues from his office in the Baltimore area. He has more than 25 years of experience in the business and is always looking for the next scoop. He has worked...
Read more from Darryl K. Taft
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.