Python 3.15 Beta 2

Python 3.15 Beta 2 Aims to Slash App Startup Times

Python 3.15 Beta 2 Aims to Slash App Startup Times

The Python development team has released the second beta of version 3.15, marking a significant milestone in the language’s evolution. With features now frozen and the release candidate phase approaching, Python 3.15 Beta 2 delivers a suite of performance improvements and developer experience enhancements—chief among them, a dramatic reduction in application startup times through explicit lazy imports .

The Startup Time Problem

Large Python applications have long suffered from slow startup times. The root cause lies in Python’s eager import system: when a module is imported, Python must locate the file, read it from disk, compile it to bytecode, and execute all top-level code . For applications with deep dependency trees—common in web frameworks, CLI tools, and data science projects—this process can take multiple seconds, even when most imported code is never actually used during a particular run.

Consider a typical CLI tool that imports a dozen heavy libraries at startup, but only uses two of them for the specific command being executed. The remaining ten modules still load, parse, and compile—wasting time and memory. This inefficiency has been a persistent pain point, particularly for command-line utilities where perceived responsiveness directly impacts user experience.

PEP 810: Explicit Lazy Imports

Python 3.15 introduces a cleaner solution through explicit lazy imports, formalized in PEP 810. The new lazy soft keyword allows developers to defer module loading until the imported name is first accessed .

How it works:

When you mark an import as lazy, Python creates a lightweight proxy object instead of immediately loading the module. The actual loading happens transparently when you first use the imported name :

lazy import json
lazy from pathlib import Path

print("Starting up...")  # json and pathlib not loaded yet

data = json.loads('{"key": "value"}')  # json loads here
p = Path(".")  # pathlib loads here

This approach gives developers the organizational benefits of declaring all imports at the top of the file—maintaining readability and conventional style—while only paying the loading cost for modules that are actually used.

Performance impact:

The performance benefits can be substantial, particularly for CLI tools and API services. One documented example shows a CLI tool that imported a heavy JSON processor at startup, adding 300ms of latency even when processing simple requests. With lazy imports, that 300ms delay is eliminated entirely—the module loads only when the heavy processing path is actually needed .

Global Control and Advanced Filtering

Python 3.15 provides multiple ways to enable lazy imports beyond individual lazy keywords in source code :

Command-line option:

python -X lazy_imports=all your_script.py

Environment variable:

export PYTHON_LAZY_IMPORTS=all

Runtime configuration:

import sys
sys.set_lazy_imports("all")  # Makes all imports lazy by default

For more selective control, sys.set_lazy_imports_filter() accepts a callable that determines whether a specific module should be loaded lazily. This enables patterns like making only your application’s own modules lazy while keeping third-party dependencies eager :

import sys

def myapp_filter(importing, imported, fromlist):
    return imported.startswith("myapp.")
sys.set_lazy_imports_filter(myapp_filter)
sys.set_lazy_imports("all")

import myapp.slow_module  # lazy (matches filter)
import json               # eager (does not match filter)

Backward compatibility:

For projects that need to support Python versions older than 3.15 while still using lazy imports on newer versions, modules can define __lazy_modules__ as a container of fully qualified module name strings. Regular import statements for those modules are then treated as lazy, with the same semantics as the lazy keyword :

__lazy_modules__ = ["json", "pathlib"]

import json     # lazy
import os       # still eager

Restrictions:

The lazy keyword has some limitations to be aware of :

  • Only permitted at module scope (using it inside functions, class bodies, or try/except blocks raises a SyntaxError)
  • Star imports cannot be lazy (lazy from module import * is invalid)
  • Future imports cannot be lazy

JIT Compiler: Significant Performance Gains

Beyond lazy imports, Python 3.15 Beta 2 delivers meaningful performance improvements through a significantly upgraded just-in-time (JIT) compiler. The experimental JIT introduced in Python 3.14—which sometimes made code run slower—has been substantially refined .

Performance numbers:

The Python team now reports :

  • 8-9% geometric mean performance improvement on x86-64 Linux over the standard interpreter
  • 12-13% speedup on AArch64 macOS over the tail-calling interpreter

These numbers represent the geometric mean across benchmarks—individual workloads may show different results, and some code may still run up to 15% slower. The JIT improvements are notable because they require no code changes from developers; the performance gains are automatic .

Tail-calling interpreter:

The official Windows 64-bit binaries now use the tail-calling interpreter by default, which reduces stack frame overhead during deep function calls and improves memory efficiency .

Tachyon: Zero-Overhead Profiling

Python 3.15 introduces a new sampling profiler called Tachyon, included as part of PEP 799. Unlike traditional profilers that instrument function calls (adding overhead that affects performance), Tachyon works by capturing stack traces from running processes .

The approach “provides virtually zero overhead while achieving sampling rates of up to 1,000,000 Hz” and can be used to debug performance issues in production environments . This represents a significant advancement in Python’s observability tooling, making it practical to profile applications in high-performance or production contexts where traditional instrumentation would be too intrusive.

Additional Performance and Developer Experience Improvements

Frame pointers enabled by default (PEP 831):

Frame pointers are now enabled by default, improving system-level observability for debuggers and crash reporters. This makes it easier to profile and debug Python applications at the system level, particularly in performance-critical environments .

UTF-8 as default encoding (PEP 686):

Python 3.15 now uses UTF-8 as the default encoding across all platforms, removing a long-standing source of locale-related bugs on Windows and older Linux distributions. While explicit encoding is still recommended for best compatibility, this change simplifies cross-platform development and reduces encoding-related surprises .

Package startup configuration files (PEP 829):

Projects can now define initialization parameters without touching environment variables or command-line flags, simplifying deployment scripts and configuration management .

The Beta Release and What It Means for Developers

Python 3.15.0b2 is the second of four planned beta releases, with the release candidate phase scheduled for August 4, 2026 . The feature freeze is now in effect, meaning no new features will be added before the final release—only bug fixes and stability improvements.

Important notes for developers:

The Python team strongly encourages maintainers of third-party Python projects to test with 3.15 during the beta phase and report issues to the Python bug tracker . This is particularly important for C extension authors, as the free-threaded stable ABI changes may affect compatibility .

Production readiness:

Beta releases are preview builds and are not recommended for production deployment. The ABI is not yet stable—pending shifts will likely break production dependencies before the August code freeze locks everything down . Developers should spin up isolated test environments to verify wheel compatibility and report regressions before the final release goes live.

Strategic Significance

Python 3.15 represents a different kind of release compared to the dramatic changes of 3.14 (free-threaded GIL removal). As one commentator noted, it’s not a “feature explosion” version—rather, it’s a “engineering completion” release that absorbs best practices from the broader ecosystem into the language infrastructure .

Key strategic themes:

Performance matters: Lazy imports address a real pain point for thousands of Python applications, particularly in the CLI and API service space. Combined with JIT improvements, these changes deliver tangible performance gains without requiring significant code rewrites.

Observability and profiling: The addition of Tachyon and default frame pointers signals Python’s growing maturity in production environments, where performance monitoring and debugging are critical.

Incremental improvement: The release demonstrates a disciplined approach to language evolution—adopting well-understood patterns (lazy loading, immutable data structures) as first-class language features rather than relying on third-party workarounds.

Ecosystem readiness: The beta phase explicitly calls on library maintainers to test compatibility, recognizing that Python’s value depends on a thriving ecosystem of third-party packages.

Conclusion

Python 3.15 Beta 2 delivers exactly what the title promises: meaningful reductions in application startup times, achieved through PEP 810’s explicit lazy imports and significant JIT compiler improvements. For developers of CLI tools, API services, and any application with deep import dependency trees, these changes translate directly to faster perceived performance and better resource utilization.

The release also demonstrates Python’s continued evolution as a high-performance, production-ready language. Features like the Tachyon profiler, default frame pointers, and UTF-8 encoding improvements speak to the language’s growing role in performance-critical and cross-platform environments.

With the feature freeze now in effect and the release candidate phase approaching, the shape of Python 3.15 is clear. For developers, the message is simple: test your projects with the beta, report issues, and prepare for a release that makes Python faster, more observable, and more developer-friendly. The final version is scheduled for October 2026—and if the beta is any indication, it will be worth the wait .

Here are short backlink-style references for Python 3.15, based on the provided search results:


Python 3.15 Beta 2: Official & Core References


Feature Specifications (PEPs)


Additional Context