diff --git a/kitty/entry_points.py b/kitty/entry_points.py index f8e75b922..03a7a7a5a 100644 --- a/kitty/entry_points.py +++ b/kitty/entry_points.py @@ -150,6 +150,12 @@ def main() -> None: if first_arg.startswith('+'): namespaced(['+', first_arg[1:]] + sys.argv[2:]) else: + # Garbage collection during startup costs ~10ms and finds almost + # nothing to collect, so disable it until the main loop starts, + # see _run_app() in main.py + import gc + + gc.disable() from kitty.main import main as kitty_main kitty_main() diff --git a/kitty/main.py b/kitty/main.py index 74e0f5336..acc99f7f2 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # License: GPL v3 Copyright: 2016, Kovid Goyal +import gc import json import locale import os @@ -401,6 +402,12 @@ def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = (), _('The startup session was invalid'), _('Loading the start session file {0} failed, with error:\n{1}').format(startup_session_error[1], startup_session_error[0]), ) + # Garbage collection is disabled during startup, see main() in + # entry_points.py. Move all objects created during startup, which are + # mostly long lived, out of the purview of the garbage collector, so + # that they are not repeatedly scanned and re-enable it. + gc.freeze() + gc.enable() try: boss.child_monitor.main_loop() finally: