The Future of Python: New Features in 3.12 Revealed by Meta

With major assistance from Meta, Python 3.12 is now officially available and boasts many new features and performance enhancements. This release demonstrates Meta’s dedication to the global developer community and its ongoing efforts to improve Python.

Meta’s Commitment to 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 based at Instagram within Meta, in a blog post about Meta’s contribution to Python 3.12.

Python is the most used programming language at Meta, considering its use in AI/ML projects for the innovation of PyTorch—a machine learning framework employed in, but not limited to, computer vision and natural language processing. It also backs the services that power Meta and the server stack at Instagram.

Immortal Objects:

One of the most visible new features in Python 3.12, courtesy of Meta, is Immortal Objects as covered by Python Enhancement Proposal (PEP) 683. Immortal Objects are created and then are passed beyond any more participation of reference counting for the remainder of their life—that is, until the shutdown of the Python interpreter. 

Instigated by a desire to reduce memory consumption in the Instagram web server, the work focused on the removal of copy-on-writes triggered by reference count updates.

The true immutable Python objects can be safely shared between interpreters — without the need for locks, be it GIL — truly improving Python’s single-process parallelism for multi-threading and multi-sub-interpreter environments.

Type System Improvements:

It was the work of the engineering team at Meta behind Pyre, an open-source Python type checker, to write and implement PEP 698. This introduces a `@typing.override` decorator to assist in refactoring class inheritance by developers without bugs. This assures static type checkers that if there is a new method in the base class that collides with the overridden method, it will result in the developer getting adequate warnings, thereby preventing the accidental dead code that used to make the life of the code maintainers quite troublesome.

Performance Optimizations:

Faster Comprehensions:

In the past, all comprehensions of Python were implicit nested functions. This means that whenever list, dict, and set comprehensions are called they will make and clean up a bunch of function objects in serving their only purpose. According to PEP 709, this fact is now different since list, dict, and set comprehensions are inlined. Consequently, this can increase the performance by up to two times. The by-product of the update is that there was a bug in the bytecode compiler that can now be exposed and fixed or hidden for unseen.

Eager Asyncio Tasks:

Python 3.12 now introduces eager asyncio tasks so that runtime overhead can be reduced when writing async code. This will allow functions directly awaited to return values without awake coroutine objects, thus making this fully async codebase more efficient.

Faster Calls to Super():

The new LOAD_SUPER_ATTR opcode makes super().attr and super().method(.) calls more efficient by reducing runtime overhead when using single-use “super” objects.

New Benchmarks:

Benchmarks in the Python Performance Benchmark suite added by Meta to be a better representative of real-world workloads, include:

  • Async_tree benchmarks to model asyncio-heavy workloads.
  • Benchmarks that test comprehensions or super() call more fully.
  • The added benefit of these adds is the assurance of effective Python optimizations in dealing with diverse scenarios.

Cinder Hooks: 

Meta had added lots of hooks to the Cinder JIT compiler, with Python 3.12, for third-party JIT compilers and run-time optimizers support.

  • API to set Python Function vectorcall entrypoint allowing to take over execution from JIT.
  • Dictionary Watchers, Type Watchers, Function Watchers, and Code Object Watchers for DKC/DRY.
  • Extensibility in the code generator to support Static Python.
  • A thread-safe API to write to perf-map files and help profile JIT-generated code.

Coming next:

The contributions for Python 3.12 happen to be only one slice of Meta’s ongoing interest in—and commitment to—the Python community. The organizational level of policy engagement is with the Steering Council, discussing PEP 703, in which the GIL is discarded to buck up true multi-threading for Python. The game-changer is in the update that Python users will experience in a multi-threading environment.

Meta is involved with more than just writing code. The company supports a Developer in Residence program for Python and sponsors events like PyCon US to share knowledge and advancements with the community.

 

Conclusion:

Hire Python developers in india for new functionalities and performance improvements in Python 3.12 through Meta is now going to be very valuable to developers. Be you’re looking to hire dedicated Python programmers, need any services like custom Python development, or collaborate with a Python development company in India, the new improvements are going to be handy in building more productive and scalable apps.

Hire dedicated Python developers and take your business to the next level with our custom Python development services. Partner with Tuvoc Technologies, the premier Python development company in India, and experience the difference.