In 2016 I wrote a script which measures how many recursive operations can Python do before crash (Fastcall uses more C stack · Issue #73044 · python/cpython · GitHub, Reduce stack consumption of PyObject_CallFunctionObjArgs() and like · Issue #73056 · python/cpython · GitHub). It was used to find and fix some regressions in 3.7. It is now available at https://github.com/serhiy-storchaka/python-misc/blob/main/stack_overflow.py.
It is interesting to look how stack consumption was changed with Python versions. Here are results for the debug build on Linux for Python from 3.3 to future 3.13. Release builds have lesser stack consumption and allows deeper recursion. On Windows the stack size is smaller.
3.3 | 3.4 | 3.5 | 3.6 | 3.7 | 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | main | |
---|---|---|---|---|---|---|---|---|---|---|---|
test_ast_parse | 87154 | 130804 | 130877 | 130877 | 130804 | 130877 | 104731 | 104658 | 130877 | 2994 (104684) | 2992 (104684) |
test_chain | 65397 | 174459 | 261762 | 261616 | 261762 | 261762 | 261762 | 261762 | 261762 | 174459 | 261762 |
test_compile | 32693 | 104658 | 130804 | 130804 | 130804 | 87227 | 87227 | 74771 | 74698 | 2995 (87203) | 2995 (87251) |
test_deepcopy | 1390 | 8176 | 8305 | 6541 | 6234 | 6229 | 6709 | 7072 | unlimited | unlimited | unlimited |
test_eq | 26142 | 52327 | 52327 | 52363 | 43650 | 43613 | 43613 | 40243 | 40243 | 1498 (34909) | 1498 (34909) |
test_filter | 104658 | 130877 | 130804 | 104731 | 104658 | 104731 | 74771 | 74771 | 104731 | 104658 | 104731 |
test_hash | 65397 | 104731 | 104658 | 104731 | 104731 | 104731 | 130950 | 104658 | 104731 | 104731 | 104731 |
test_islice | 104585 | 174459 | 174459 | 174459 | 174459 | 174459 | 174605 | 174459 | 174605 | 74698 | 74771 |
test_json_dump | 40170 | 58149 | 58148 | 58148 | 58148 | 58148 | 58149 | 40243 | 52363 | 1497 (52342) | 1497 (52340) |
test_json_load | 43540 | 58112 | 58149 | 58149 | 58149 | 58149 | 52327 | 58149 | 47603 | 1497 (43646) | 1497 (43622) |
test_map | 65397 | 130877 | 130877 | 74698 | 74771 | 74771 | 65470 | 65397 | 65433 | 65433 | 65433 |
test_marshal_dump | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 |
test_marshal_load | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 | 1999 |
test_partial | 58112 | 87227 | 87227 | 65433 | 65433 | 65470 | 74771 | 65397 | 65470 | 1497 (58151) | 1497 (58151) |
test_pickle_dump | 32693 | 47603 | 47604 | 47567 | 43613 | 43613 | 40280 | 29089 | 37380 | 749 (32711) | 749 (32711) |
test_python_call | 2314 | 8871 | 8176 | 7368 | 7812 | 8180 | 8871 | 8724 | 9874 | 498 (8304) | 498 (8049) |
test_python_call_keyword | 2314 | 8867 | 8176 | 7376 | 7812 | 8176 | 8875 | 8725 | 9875 | 498 (8310) | 498 (8055) |
test_python_function | 2616 | 13779 | 13779 | 13084 | 12463 | 12463 | 13430 | 14151 | unlimited | unlimited | unlimited |
test_python_generator | 3079 | 24934 | 20136 | 22768 | 21799 | 21799 | 22768 | 16362 | 18684 | unlimited | unlimited |
test_python_getitem | 2294 | 8176 | 7586 | 6978 | 8180 | 9182 | 11896 | 13084 | unlimited | 107070 (unlimited) | 107070 (unlimited) |
test_python_iterator | 2161 | 7072 | 6460 | 5627 | 6983 | 8445 | 10908 | 10469 | 15870 | 749 (11897) | 749 (11897) |
test_python_method | 2615 | 13779 | 13770 | 13084 | 12463 | 12463 | 13421 | 14151 | unlimited | unlimited | unlimited |
test_repr | 52327 | 65397 | 65433 | 65397 | 65433 | 65469 | 58149 | 65397 | 65433 | 1496 (52342) | 1496 (52342) |
test_yield_from | 3096 | 24934 | 20136 | 22750 | 21799 | 21799 | 22750 | 14535 | 16362 | 74771 | 65397 |
As a rule, stack consumption remained the same. In some cases, it got better with each version. I highlighted in bold cases when it got worse.