Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow startup, possibly due to too many calls to getpid() #2754

Closed
misev opened this issue Jun 8, 2020 · 9 comments
Closed

Slow startup, possibly due to too many calls to getpid() #2754

misev opened this issue Jun 8, 2020 · 9 comments
Labels

Comments

@misev
Copy link

misev commented Jun 8, 2020

Describe the bug
kitty takes ~0.6s to start on my machine which is perceptibly quite slow.
I ran it with strace which showed that most of the time is spent in a lot of (~80,000) calls to getpid()

293934 1591634753.176957 brk(0x202d000) = 0x202d000 <0.000010>
293934 1591634753.182584 brk(0x204e000) = 0x204e000 <0.000012>
293934 1591634753.185616 getpid()       = 293934 <0.000008>
293934 1591634753.185649 getpid()       = 293934 <0.000006>
293934 1591634753.185679 getpid()       = 293934 <0.000006>
293934 1591634753.185715 getpid()       = 293934 <0.000006>
293934 1591634753.185741 getpid()       = 293934 <0.000005>
293934 1591634753.185769 getpid()       = 293934 <0.000004>
...
293934 1591634754.457158 getpid()       = 293934 <0.000003>
293934 1591634754.457171 getpid()       = 293934 <0.000003>
293934 1591634754.457184 getpid()       = 293934 <0.000003>
293934 1591634754.457197 getpid()       = 293934 <0.000003>
293934 1591634754.457210 getpid()       = 293934 <0.000003>
293934 1591634754.457223 getpid()       = 293934 <0.000003>
293934 1591634754.457236 getpid()       = 293934 <0.000003>

You can check with strace -f -ttt -T -o strace-analysis.txt kitty

Expected behavior
The startup is perceptibly slow, I'd expect it to be faster. The --single-instance option makes no difference.

Enviroment details
OS: Kubuntu 20.04

kitty 0.17.4 (3d32202b3a) created by Kovid Goyal
Linux hifi 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64
Ubuntu 20.04 LTS \n \l
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04 LTS"
Loaded config files: /etc/xdg/kitty/kitty.conf, /home/dimitar/.config/kitty/kitty.conf
Running under: X11

Config options different from defaults:
active_tab_title_template  {title}
allow_remote_control       y
background                 Color(red=28, green=40, blue=54)
bold_font                  Iosevka Term Heavy
bold_italic_font           Iosevka Term Heavy Italic
color1                     Color(red=249, green=85, blue=95)
color10                    Color(red=52, green=187, blue=153)
color11                    Color(red=255, green=255, blue=85)
color12                    Color(red=88, green=156, blue=245)
color13                    Color(red=231, green=85, blue=152)
color14                    Color(red=57, green=120, blue=187)
color2                     Color(red=32, green=175, blue=137)
color3                     Color(red=253, green=240, blue=41)
color4                     Color(red=88, green=156, blue=245)
color5                     Color(red=147, green=77, blue=149)
color6                     Color(red=30, green=158, blue=230)
color7                     Color(red=187, green=187, blue=187)
color8                     Color(red=84, green=84, blue=84)
color9                     Color(red=250, green=139, blue=142)
cursor                     Color(red=187, green=187, blue=187)
enable_audio_bell          False
font_family                Iosevka Term Medium
font_size                  12.0
foreground                 Color(red=255, green=255, blue=255)
italic_font                Iosevka Term Medium Italic
repaint_delay              16
scrollback_lines           50000
select_by_word_characters  :@-./_~?&=%+#
selection_background       Color(red=180, green=213, blue=255)
selection_foreground       Color(red=28, green=40, blue=54)
single_window_margin_width FloatEdges(left=-1000.0, top=-1000.0, right=-1000.0, bottom=-1000.0)
strip_trailing_spaces      smart
tab_bar_edge               1
window_margin_width        FloatEdges(left=1.0, top=1.0, right=1.0, bottom=1.0)
Added shortcuts:
	control+page_up KeyAction(func='previous_tab', args=())
	control+page_down KeyAction(func='previous_tab', args=())
Changed shortcuts:
	shift+control+w KeyAction(func='close_tab', args=())

Additional context
kitty --config NONE doesn't change the startup time.

@misev misev added the bug label Jun 8, 2020
@kovidgoyal
Copy link
Owner

kitty doesnt have any calls to getpid() at all, grep the codebase for it
and you will see exactly 4 instances, exactly one of which is called
during normal startup exactly once. I have no idea where the getpids are
coming from but it isnt kitty code. And while I do see the large number of
getpids() in my strace too, so it would be interesting to track them
down, they dont cause a slowdown for me.

time kitty false

real 0.344
user 0.241
sys 0.076
maxmem 80 MB
faults 0

And with single instance it is instantaneous, for all calls after teh
first

time kitty -1

real 0.097
user 0.086
sys 0.010
maxmem 21 MB
faults 0

@kovidgoyal
Copy link
Owner

For the getpids() they are happening somewhere in the course of
create_os_window() in glfw.c

@kovidgoyal
Copy link
Owner

And further they come from glfwCreateWindow

@kovidgoyal
Copy link
Owner

And as far as I can tell the getpids come from glXGetFBConfigAttrib()
which is a LGX library function. Nothing kitty can do about this as far
as I can see. It would be nice if GLX provided an API to get fraebuffer
config attribs in bulk but as far as I can tell it doesnt.

@kovidgoyal
Copy link
Owner

One possible mitigation would be to cache the results of
chooseGLXFBConfig, that would reduce the number of getpids() to a
quarter

kovidgoyal added a commit that referenced this issue Jun 8, 2020
… configurations once

On my system reduces the number of getpid() calls from 67982 to 17327
I dont know why get framebuffer config attributes requires getpid() and
why it is so slow, probably a driver bug. Fixes #2754
@misev
Copy link
Author

misev commented Jun 8, 2020

Right, it was most plausible that the getpids are likely from some library and not kitty itself. Great that you found a way to reduce them, I'm curious if it in turn reduces the startup time.
The original startup time I reported was on an older machine from 2012, now testing on a recent one I get a similar timing of 0.33s.

@kovidgoyal
Copy link
Owner

On my machine startup time was reduced by abt 25%

@kovidgoyal
Copy link
Owner

And by using an API from GLX 1.3 I have the number of getpids() down to
the hunreds.

@misev
Copy link
Author

misev commented Jun 9, 2020

Great, I just tried master and can confirm it's ~25% faster!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants