Improve python GC behavior

This commit is contained in:
Matthias
2022-11-12 15:39:54 +01:00
parent e6172a68d7
commit 7adca97358
2 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import gc
import logging
import platform
logger = logging.getLogger(__name__)
def gc_set_threshold():
"""
Reduce number of GC runs to improve performance (explanation video)
https://www.youtube.com/watch?v=p4Sn6UcFTOU
"""
if platform.python_implementation() == "CPython":
# allocs, g1, g2 = gc.get_threshold()
gc.set_threshold(50_000, 500, 1000)
logger.debug("Adjusting python allocations to reduce GC runs")