mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 22:55:29 +00:00
Do not import the launch module when there are no watchers
Creating the first window imported kitty.launch, which is slow to import, just to find out there are no watchers to load. This delayed the launch of the first child by a few ms.
This commit is contained in:
parent
e17a8383a6
commit
ed21ef4f95
2 changed files with 11 additions and 5 deletions
|
|
@ -776,13 +776,17 @@ class GlobalWatchers:
|
|||
raw_spec = get_options().watcher
|
||||
if raw_spec == self.options_spec:
|
||||
return self.ans
|
||||
from .launch import load_watch_modules
|
||||
|
||||
spec = raw_spec.copy()
|
||||
if self.extra:
|
||||
spec[self.extra] = self.extra
|
||||
ans = load_watch_modules(spec.keys())
|
||||
self.ans = Watchers() if ans is None else ans
|
||||
if spec:
|
||||
# Importing launch is slow, so do it only when there are watchers
|
||||
from .launch import load_watch_modules
|
||||
|
||||
ans = load_watch_modules(spec.keys())
|
||||
self.ans = Watchers() if ans is None else ans
|
||||
else:
|
||||
self.ans = Watchers()
|
||||
self.options_spec = raw_spec.copy()
|
||||
return self.ans
|
||||
|
||||
|
|
|
|||
|
|
@ -1751,10 +1751,12 @@ class TestWindowHelpers(BaseTest):
|
|||
opts.watcher = {'a.py': 'a.py'}
|
||||
self.assertIs(g(), w1)
|
||||
opts.watcher = {}
|
||||
num_calls = len(calls)
|
||||
ans = g()
|
||||
self.assertIsNot(ans, w1)
|
||||
self.assertIsInstance(ans, Watchers)
|
||||
self.ae(calls[-1], ())
|
||||
# with no watchers, the slow to import launch module is not used
|
||||
self.ae(len(calls), num_calls)
|
||||
# changing the extra watcher after first use must take effect
|
||||
g.set_extra('y.py')
|
||||
self.assertIs(g(), w1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue