From 48ec718757d59932749d177bdecf05b3b3ed00a5 Mon Sep 17 00:00:00 2001 From: Hellow Date: Tue, 4 Apr 2023 22:07:56 +0200 Subject: [PATCH] made gc modification optional --- src/music_kraken/__init__.py | 27 ++++++++++++++------------- src/music_kraken/utils/shared.py | 7 ++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 73c6165..d043b19 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -4,22 +4,23 @@ import logging import re from . import objects, pages -from .utils.shared import MUSIC_DIR, NOT_A_GENRE, get_random_message +from .utils.shared import MUSIC_DIR, NOT_A_GENRE, MODIFY_GC, get_random_message -""" -At the start I modify the garbage collector to run a bit fewer times. -This should increase speed: -https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/ -""" -# Clean up what might be garbage so far. -gc.collect(2) +if MODIFY_GC: + """ + At the start I modify the garbage collector to run a bit fewer times. + This should increase speed: + https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/ + """ + # Clean up what might be garbage so far. + gc.collect(2) -allocs, gen1, gen2 = gc.get_threshold() -allocs = 50_000 # Start the GC sequence every 50K not 700 allocations. -gen1 = gen1 * 2 -gen2 = gen2 * 2 -gc.set_threshold(allocs, gen1, gen2) + allocs, gen1, gen2 = gc.get_threshold() + allocs = 50_000 # Start the GC sequence every 50K not 700 allocations. + gen1 = gen1 * 2 + gen2 = gen2 * 2 + gc.set_threshold(allocs, gen1, gen2) logging.getLogger("musicbrainzngs").setLevel(logging.WARNING) musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader") diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 9242d98..db14988 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -7,6 +7,11 @@ from sys import platform as current_os from pathlib import Path import random +# modifies the garbage collector to speed up the program +# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/ +# https://web.archive.org/web/20221124122222/https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/ +MODIFY_GC: bool = True + """ I will now and then use those messages in the programm. But I won't overuse them dw. @@ -22,7 +27,7 @@ HAPPY_MESSAGES: List[str] = [ "🏳️‍⚧️🏳️‍⚧️ Trans women are women, trans men are men. 🏳️‍⚧️🏳️‍⚧️", "🏴‍☠️🏴‍☠️ Unite under one flag, fuck borders. 🏴‍☠️🏴‍☠️", "Join my Matrix Space: https://matrix.to/#/#music-kraken:matrix.org", - "Gotta love the BPJM!! :/" + "Gotta love the BPJM!! >:(" ]