mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-20 23:25:46 +00:00
Disable garbage collection during startup
Python garbage collections triggered while importing modules, parsing the config and creating the first window cost ~10ms and find almost nothing to collect. Disable the collector until the main loop starts, then freeze the, mostly long lived, objects created during startup so they are not repeatedly scanned by later collections.
This commit is contained in:
parent
a2af3dadea
commit
e17a8383a6
2 changed files with 13 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue