Back to Blog
    Programming Languages

    Python 3.13: Free-Threaded Mode, JIT Compiler & Every New Feature Explained

    Mortex Solutions TeamFebruary 10, 202613 min read
    Python 3.13: Free-Threaded Mode, JIT Compiler & Every New Feature Explained

    Python 3.13 is a landmark release that tackles Python's two biggest performance limitations: the Global Interpreter Lock (GIL) and the lack of just-in-time compilation. Here's everything developers need to know.

    Python programming code

    🐍 The GIL is Finally Optional

    Python 3.13 introduces a free-threaded build (also called "no-GIL" mode) that allows true multi-threaded parallelism. This is the most requested Python feature in history.

    import threading
    import time
    
    # With free-threaded Python, these actually run in parallel!
    def cpu_work(n):
        total = 0
        for i in range(n):
            total += i * i
        return total
    
    threads = [threading.Thread(target=cpu_work, args=(10_000_000,)) for _ in range(4)]
    
    start = time.time()
    for t in threads:
        t.start()
    for t in threads:
        t.join()
    
    print(f"Completed in {time.time() - start:.2f}s")
    # Free-threaded: ~0.8s (4 cores)
    # GIL mode: ~3.2s (single core)

    How to Enable Free-Threaded Mode

    # Install free-threaded build
    # On macOS/Linux:
    python3.13t  # 't' suffix = free-threaded
    
    # Check if GIL is disabled
    import sys
    print(sys._is_gil_enabled())  # False in free-threaded build

    ⚡ JIT Compiler (Experimental)

    Python 3.13 includes an experimental copy-and-patch JIT compiler that can speed up CPU-bound code by 2-9%.

    # Enable JIT at build time
    # ./configure --enable-experimental-jit
    # or set PYTHON_JIT=1 environment variable
    
    # No code changes needed — the JIT optimises hot loops automatically
    def fibonacci(n):
        a, b = 0, 1
        for _ in range(n):
            a, b = b, a + b
        return a
    
    # JIT makes this ~5% faster on average

    Improved Error Messages

    Python 3.13 continues improving error messages with colourful tracebacks and better suggestions.

    # Colour-coded tracebacks (in terminal)
    Traceback (most recent call last):
      File "app.py", line 10, in <module>
        result = process_data(data)
                 ^^^^^^^^^^^^^^^^^^
      File "app.py", line 5, in process_data
        return data["users"][0]["name"]
               ~~~~^^^^^^^^
    TypeError: list indices must be integers or slices, not str
    
    # Did you mean 'data["users"]' instead of 'data["users"][0]'?

    New typing Features

    from typing import TypeIs, ReadOnly
    
    # TypeIs — better type narrowing than TypeGuard
    def is_string(value: object) -> TypeIs[str]:
        return isinstance(value, str)
    
    # ReadOnly for TypedDict
    from typing import TypedDict
    
    class Config(TypedDict):
        name: str
        debug: ReadOnly[bool]  # Cannot be modified after creation
    
    # Deprecated decorator
    from warnings import deprecated
    
    @deprecated("Use new_function() instead")
    def old_function():
        pass

    Interactive Interpreter Improvements

    • Multi-line editing with history
    • Colour-coded output
    • Better paste support for code blocks
    • F2 to edit in visual mode
    🐍 Key Takeaway: Python 3.13 is a performance-focused release. The free-threaded build is experimental but marks the beginning of Python's multi-core future. Start testing your libraries for compatibility now.