From 4eabccbaf359b0a79625a7ee39520ff33a359151 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Nov 2026 06:42:59 +0530 Subject: [PATCH] Import the boss, session and shader modules after initializing glfw These modules are slow to import, so import them in _run_app() and load_all_shaders() instead of at the top of kitty/main.py, so that on Wayland they are imported while the GPU driver is loaded in a thread started by init_glfw(), instead of before it. Previously the driver thread overlapped only with loading fonts and the main thread then had to wait ~10ms for it. Now it finishes well before the first OS Window is created. --- kitty/main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kitty/main.py b/kitty/main.py index acc99f7f2..430a9d659 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -12,7 +12,6 @@ from contextlib import contextmanager, suppress from gettext import gettext as _ from . import logout_session -from .boss import Boss from .child import set_default_env, set_LANG_in_default_env from .cli import create_opts, parse_args from .cli_stub import CLIOptions @@ -69,8 +68,6 @@ from .logout_session import ( from .options.types import Options, defaults from .options.utils import DELETE_ENV_VAR from .os_window_size import edge_spacing, initial_window_size_func -from .session import create_sessions, get_os_window_sizing_data -from .shaders.slang import load_shader_programs from .types import LayerShellConfig from .utils import ( cleanup_ssh_control_masters, @@ -100,6 +97,8 @@ def set_custom_ibeam_cursor() -> None: def load_all_shaders() -> None: + from .shaders.slang import load_shader_programs # see _run_app() for why this is not imported at the top + try: load_shader_programs() except ValueError as err: @@ -315,6 +314,13 @@ def logout_snapshot_to_restore(opts: Options, args: CLIOptions) -> RestoredSnaps def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = (), talk_fd: int = -1) -> None: + # These modules are slow to import and are imported here rather than at + # the top of this module, so that they are imported after init_glfw(), + # which on Wayland loads the GPU driver in a thread, see glfw_init() + # in glfw.c, while they are being imported. + from .boss import Boss + from .session import create_sessions, get_os_window_sizing_data + global _is_panel_kitten _is_panel_kitten = run_app.cached_values_name == 'panel' if _is_panel_kitten and run_app.layer_shell_config and run_app.layer_shell_config.output_name in ('list', 'listjson'):