From 7adca9735862e1f186f8a6150bcdfca42c067e2c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 12 Nov 2022 15:39:54 +0100 Subject: [PATCH] Improve python GC behavior --- freqtrade/main.py | 3 +++ freqtrade/util/gc_setup.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 freqtrade/util/gc_setup.py diff --git a/freqtrade/main.py b/freqtrade/main.py index 754c536d0..0a46747ea 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -7,6 +7,8 @@ import logging import sys from typing import Any, List +from freqtrade.util.gc_setup import gc_set_threshold + # check min. python version if sys.version_info < (3, 8): # pragma: no cover @@ -36,6 +38,7 @@ def main(sysargv: List[str] = None) -> None: # Call subcommand. if 'func' in args: logger.info(f'freqtrade {__version__}') + gc_set_threshold() return_code = args['func'](args) else: # No subcommand was issued. diff --git a/freqtrade/util/gc_setup.py b/freqtrade/util/gc_setup.py new file mode 100644 index 000000000..a3532cbab --- /dev/null +++ b/freqtrade/util/gc_setup.py @@ -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")