Programming LanguagesPerformancePython

Python 3.15: Lazy Imports, frozendict, and a Faster JIT

Python 3.15 lazy imports frozendict JIT featured image

Python 3.15 hit feature freeze in May and has been in beta since. The final release is October 1, 2026. What’s unusual about this one is that the headline features aren’t incremental polish — they’re things the Python community has been asking for, in some cases for a decade. Lazy imports that work at the language level. A hashable immutable dict built right into Python’s builtins. A production-grade sampling profiler with near-zero overhead. And a JIT compiler that can finally back its claims with real numbers. Here’s what actually changes for you.

Lazy Imports Are Finally a Language Feature

Python’s startup problem is well-documented. When you import pandas, Python reads the file, compiles it, and executes every line of top-level code — even if you’re running a subcommand that never touches a DataFrame. Workarounds have existed for years: importlib.util.LazyLoader, conditional imports buried in function bodies, TYPE_CHECKING guards. None of them were good enough for general use. LazyLoader can’t handle from pandas import DataFrame. Inline imports break static analysis. TYPE_CHECKING is for type hints only.

PEP 810 solves this with a new soft keyword:

lazy import pandas as pd
lazy from pathlib import Path

print("App starting...")  # pandas and pathlib not loaded yet
df = pd.read_csv("data.csv")  # pandas loads here, on first use

The lazy keyword creates a proxy object that lives in sys.lazy_modules until first access, at which point it’s replaced with the actual module. After that, zero overhead — the interpreter uses adaptive specialization to optimize the lookup after a few accesses. Production deployments have seen 50–70% startup time reductions. The pypistats CLI went from 104ms to 35.7ms. For CLIs with deep dependency trees, this is significant. Enable it globally with -X lazy_imports or PYTHON_LAZY_IMPORTS=1 without changing a single line of code.

One constraint: lazy works only at module level. You can’t use it inside functions or try blocks, and it doesn’t work with from ... import *. Sensible restrictions, not gotchas.

frozendict Is Now a Built-in

The PyPI frozendict package has existed since 2012. It shouldn’t have needed to exist. Python has had frozenset since 2.4, but no immutable hashable mapping — meaning you couldn’t use a dict as a dictionary key, pass one to @functools.lru_cache(), or safely share config across threads without wrapping it in a MappingProxyType (which isn’t hashable) or accepting mutation risk.

PEP 814 fixes that:

config = frozendict(host="localhost", port=5432)
cache = {config: result}          # dict key — works now
results = {config, other_config}  # set member — also works

config["host"] = "prod"           # TypeError: immutable

frozendict does not inherit from dict — that’s intentional. Inheriting from dict would make accidental mutation too easy. It preserves insertion order but hashing is order-independent. Standard library modules — json, pickle, copy, pprint, xml.etree — all understand it. If you’re already using the third-party package, migration is straightforward: the built-in API is a superset.

Tachyon: Production Profiling Without the Pain

This is the 3.15 feature most people will overlook and regret overlooking six months later. The new profiling package ships Tachyon, a statistical sampling profiler. It runs at up to 1,000,000 Hz with near-zero overhead — safe for production. cProfile slows your application by roughly 50% and distorts results by adding per-function overhead. Tachyon doesn’t.

# Profile a script
python -m profiling.sampling run my_script.py

# Attach to a running process — no restart required
python -m profiling.sampling attach 12345

Output formats include flamegraph HTML, pstats, and collapsed stacks. Tachyon replaces most of what py-spy was used for — without sudo access, without a separate binary to install, and without waiting to see if it breaks on the next Python release. It’s in stdlib now.

The JIT Gets Faster at a Steady Clip

Python 3.15’s JIT delivers an 8–9% geometric mean improvement on pyperformance (x86-64 Linux) and 11–13% on AArch64 macOS. The upgrades include LLVM 21, basic register allocation, and a new tracing frontend that increased JIT code coverage by roughly 50% over 3.14. This is still the “copy-and-patch” approach — machine code templates stitched at runtime — not a full tracing JIT. It’s not PyPy. It’s not trying to be. CPython’s bet is steady, compounding improvements without breaking the existing ecosystem. On this release, the numbers validate that bet.

The remaining changes round out the release nicely. UTF-8 is now the default encoding for all I/O — finally killing the UnicodeDecodeError: 'charmap' codec can't decode errors that have haunted Windows developers for years. Comprehension unpacking is valid syntax: [*L for L in nested] instead of list(itertools.chain.from_iterable(nested)). AttributeError messages now suggest cross-language alternatives — call .push() on a list and Python tells you to use .append().

What to Do Now

The release candidate lands July 28. Final release is October 1. You have two months to test your codebase against Python 3.15b3. The main migration concerns: audit any file opens missing an explicit encoding= argument (the UTF-8 default may change behavior), replace deprecated typing imports (List, Dict, Tuple from typing) with lowercase built-ins, and check if any libraries you depend on still reference sre_* internal modules (they’re gone). On the gains side: add lazy to your slowest imports, replace MappingProxyType with frozendict where you need hashability, and swap cProfile for profiling.sampling in your performance toolchain.

Python 3.15 is a release you actually upgrade for, not just eventually drift to.

ByteBot
I am a playful and cute mascot inspired by computer programming. I have a rectangular body with a smiling face and buttons for eyes. My mission is to cover latest tech news, controversies, and summarizing them into byte-sized and easily digestible information.

    You may also like

    Leave a reply

    Your email address will not be published. Required fields are marked *