Skip to content

Potentially serious regression in garbage collector performance in Python 3.14 #139951

@pgdr

Description

@pgdr

Bug report

Bug description:

The following code, consisting of a bunch of dict lookups and writes, runs in

  • < 1 second on Python 3.13
  • > 2 seconds on Python 3.14
n = 1000
d = {}
for i in range(n):
    d[(i, i)] = d[(i, 0)] = d[(0, i)] = 0
for i in range(1, n):
    for j in range(1, n):
        d[(i, j)] = i + j + d[(i - 1, j)] + d[(i, j - 1)] + d[(i - 1, j - 1)]
print(d[(n - 1, n - 1)])

Tests are run on a Dell Precision 5490, running Ubuntu:

Linux precision 6.14.0-33-generic #33-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 17 23:22:02 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

Ubuntu 25.04 (Plucky)

The cpython is from python-build-standalone

  • cpython-3.14.0+20251010-x86_64-unknown-linux-gnu-install_only.tar.gz
  • cpython-3.13.8+20251010-x86_64-unknown-linux-gnu-install_only.tar.gz

Log

[~/regression-testing]$ hyperfine --warmup=10 "cp313/python/bin/python3.13 dicttest.py" "cp314/python/bin/python3.14 dicttest.py"
Benchmark 1: cp313/python/bin/python3.13 dicttest.py
  Time (mean ± σ):     880.8 ms ± 119.7 ms    [User: 730.1 ms, System: 150.1 ms]
  Range (min … max):   713.3 ms … 1066.2 ms    10 runs
 
Benchmark 2: cp314/python/bin/python3.14 dicttest.py
  Time (mean ± σ):      2.235 s ±  0.035 s    [User: 2.066 s, System: 0.168 s]
  Range (min … max):    2.168 s …  2.295 s    10 runs
 
Summary
  cp313/python/bin/python3.13 dicttest.py ran
    2.54 ± 0.35 times faster than cp314/python/bin/python3.14 dicttest.py

It seems to scale very poorly too. With the same code, but n = 2000 (instead of n = 1000), leads to 3.3 sec (Python 3.13) vs 20 seconds (Python 3.14)! I.e., Python 3.13 being 5 times faster.

[~/regression-testing]$ hyperfine --warmup=10 "cp313/python/bin/python3.13 dicttest.py" "cp314/python/bin/python3.14 dicttest.py"
Benchmark 1: cp313/python/bin/python3.13 dicttest.py
  Time (mean ± σ):      3.458 s ±  0.048 s    [User: 2.889 s, System: 0.568 s]
  Range (min … max):    3.375 s …  3.521 s    10 runs
 
Benchmark 2: cp314/python/bin/python3.14 dicttest.py
  Time (mean ± σ):     20.084 s ±  0.230 s    [User: 19.503 s, System: 0.577 s]
  Range (min … max):   19.749 s … 20.345 s    10 runs
 
Summary
  cp313/python/bin/python3.13 dicttest.py ran
    5.81 ± 0.10 times faster than cp314/python/bin/python3.14 dicttest.py
Time comparison plot of Python 3.13 vs Python 3.14

Plotting time (in seconds) of the script run with n = 0 ... 2000.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions