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

Fish startup time increases significantly with this plugin #23

Closed
xigoi opened this issue Oct 4, 2020 · 15 comments · Fixed by #24
Closed

Fish startup time increases significantly with this plugin #23

xigoi opened this issue Oct 4, 2020 · 15 comments · Fixed by #24
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@xigoi
Copy link

xigoi commented Oct 4, 2020

After I installed this plugin (using Fisher), the startup time of Fish has increased from about 1 second to about 7 seconds. I confirmed with fish -p profile.txt that the slowdown is indeed caused by Gitnow.

@joseluisq joseluisq self-assigned this Oct 4, 2020
@joseluisq
Copy link
Owner

joseluisq commented Oct 4, 2020

It would be great if you can share your profile measurements as well as your OS and software used (OS, Fish, Fisher and Gitnow versions). Otherwise I can not verify it.
Right now on my Linux workstation it takes just 2 secs, for example create a new session (open a new tab in my terminal).

FYI, take in mind that the function __gitnow_read_config in conf.d/gitnow_config.fish file needs to read and parse the .gitnow config file but if you have no the default .gitnow (which is used as a fallback only) located at ~/.config/fish/conf.d/.gitnow, __gitnow_read_config will download that default file from this Github repository.

This download only happens once for example at installation. So it should not be relatated to your issue.

# default .gitnow file download used as workaround
if not test -e $config_file
curl -sSo $config_file https://raw.githubusercontent.com/joseluisq/gitnow/master/.gitnow
end

I use this as a workaround because Fisher has no install event (for install this file once) that's why I need to bother users with this checking and downloading. However I have addresed this on a separeted project https://github.com/joseluisq/paket.

@xigoi
Copy link
Author

xigoi commented Oct 4, 2020

Sorry, I wanted to add specs but didn't know exactly which ones you want.
OS: Android 10 with Termux (IIRC it also affects my computer with Manjaro, I'll check when I can)
Fish: 3.1.2
Fisher: 3.2.11
Gitnow: latest at this time
Result of fish -p profile.txt -c ''

@joseluisq
Copy link
Owner

After a quick review here few "expensive" calls.

# 0.1 This is not related to Gitnow
## Your profile
256	256	--> [ -f $file -a -r $file ]
1365	3544722	--> source $file
145	145	---> set -q XDG_CONFIG_HOME
106	106	---> set XDG_CONFIG_HOME ~/.config

# 0.2 This is not related to Gitnow
## My profile
54	54	--> [ -f $file -a -r $file ]
293	402596	--> source $file
26	26	---> set -q XDG_CONFIG_HOME
39	39	---> set XDG_CONFIG_HOME ~/.config


# 1.1 Your profile
805	144823	---> source "$fish_completions/__gitnow_completions.fish"
50159	143660	----> source $__fish_data_dir/completions/git.fish

# 1.2 My profile
292	34214	---> source "$fish_completions/__gitnow_completions.fish"
14271	33767	----> source $__fish_data_dir/completions/git.fish


# 2.1 Your profile
4953	3372829	-----> for line in (command cat $config_file)
            # comments: skip out comment lines
            if __gitnow_is_comment_line $line
                continue
            end

# 2.2 My profile
475	361382	-----> for line in (command cat $config_file)
            # comments: skip out comment lines
            if __gitnow_is_comment_line $line
                continue
            end


# 3.1 Your profile
120	120	-------> test has_keybindings
291	70882	-------> __gitnow_read_keybinding_line $line
1122	30610	--------> set -l pairs (echo -n $line | command sed 's/^ *//;s/ *$//')
29488	29488	---------> echo -n $line | command sed 's/^ *//;s/ *$//'
124	39981	--------> if not __gitnow_is_key_value_pair $pairs
        return

# 3.2 My profile
15	15	-------> test has_keybindings
42	15871	-------> __gitnow_read_keybinding_line $line
241	2645	--------> set -l pairs (echo -n $line | command sed 's/^ *//;s/ *$//')
2404	2404	---------> echo -n $line | command sed 's/^ *//;s/ *$//'
8	4224	--------> if not __gitnow_is_key_value_pair $pairs
        return

In general looks like parsing the .gitnow file (which happens on every new session) is slow in your Android. Specially using regexs via sed, grep or even just using cat. Also stuff made by Fish built-in functions like the first one (0.1) or another functions as well.

So for now this is not Gitnow related issue essentially compared with a Linux desktop where Gitnow/Fish runs faster.
However It would be great if you can also contrast your profile here with your desktop machine.

@xigoi
Copy link
Author

xigoi commented Oct 4, 2020

Here's the profile from my desktop computer.
Manjaro Linux
Fish 3.1.2
Fisher 3.2.11

time fish -c '': 2320 ms with Gitnow, 63 ms without Gitnow.

@joseluisq
Copy link
Owner

Here the test on my ArchLinux workstation:

~> fish -v
fish, version 3.1.2
~> fisher -v
fisher version 3.2.11 ~/.config/fish/functions/fisher.fish
~> gitnow -v
GitNow version 2.5.0
~> time fish -c ''
________________________________________________________
Executed in  450,00 millis    fish           external 
   usr time  392,93 millis  801,00 micros  392,13 millis 
   sys time   75,24 millis  231,00 micros   75,01 millis 

Last command has run in approx. 450ms.

Wierd that for you test takes more time.

@joseluisq
Copy link
Owner

joseluisq commented Oct 4, 2020

Here the slow executions of your profile.

# 1. Git completions (long file) by Fish utils is sourced by Gitnow on `__gitnow_completions.fish` file
418	98999	---> source "$fish_completions/__gitnow_completions.fish"
31708	98084	----> source $__fish_data_dir/completions/git.fish

# 2. Calling to __gitnow_read_config function is slow, this file parses the .gitnow file. 
80	1685682	---> __gitnow_read_config
167	3554	----> set gitnow_xpaste (__gitnow_get_clip_program)
49

Improvements:

I need to measure profiles, refactor the .gitnow file parsing and also see how to speed up the Git completions for Gitnow probably just using specific functions only. So I'm going to label this Github issue as enhancement.

@joseluisq
Copy link
Owner

joseluisq commented Oct 4, 2020

Tests

Just to confirm that above can you try:

  • In ~/.config/fish/conf.d/gitnow_config.fish just comment out __gitnow_read_config call, save it and then try to open a new session. Is now faster than before? can you take measures and share it?
  • In ~/.config/fish/conf.d/completions/__gitnow_completions.fish just comment out the first line source $__fish_data_dir/completions/git.fish, save it save it and then try to open a new session. Is now even faster than before? can you take measures and share it?

Could you also share you computer specs CPU,RAM? Because I guess I can not see this slowness due my specs are different than yours.

@joseluisq joseluisq added the enhancement New feature or request label Oct 4, 2020
@xigoi
Copy link
Author

xigoi commented Oct 4, 2020

You probably just have a faster machine. But 400 ms for a single plugin is still a lot, seeing that the rest of the shell (including other plugins) took less than 100 ms on my slower machine.

It's a few years old Lenovo G50-45 laptop. 8 GB RAM, 4-core AMD QC 4000 1.3 GHz.

@joseluisq
Copy link
Owner

joseluisq commented Oct 4, 2020

Yes, my specs are more high that's why I can not see the slowness. Intel Core i7 2.5GHz 8 GB RAM

@joseluisq
Copy link
Owner

joseluisq commented Oct 4, 2020

Tests

Just to confirm that above can you try:

  • In ~/.config/fish/conf.d/gitnow_config.fish just comment out __gitnow_read_config call, save it and then try to open a new session. Is now faster than before? can you take measures and share it?
  • In ~/.config/fish/conf.d/completions/__gitnow_completions.fish just comment out the first line source $__fish_data_dir/completions/git.fish, save it and then try to open a new session. Is now even faster than before? can you take measures and share it?

It would be great if you can test this by yourself, I'm trying to speed up more that parts of the plugin.

@xigoi
Copy link
Author

xigoi commented Oct 4, 2020

Sorry, I didn't see the tests previously. The first one made a drastic improvement, bringing it down to 300 ms. And with the second one, it's almost equal to the time without the plugin.

@joseluisq
Copy link
Owner

Great, as I have supposed so. The parsing is very slow and the second one is the large git completions support for Fish (utils) which is used by Gitnow (just two functions of it).
Thanks for the feedback, I will let you know here when I get some progress on this.

@joseluisq
Copy link
Owner

With 40454f9 I have gained some speed at startup (half faster).

Before:

~> time fish -c ''
________________________________________________________
Executed in  441,87 millis    fish           external 
   usr time  376,85 millis    0,00 micros  376,85 millis 
   sys time   83,83 millis  1001,00 micros   82,82 millis

After:

~> time fish -c ''
________________________________________________________
Executed in  232,03 millis    fish           external 
   usr time  187,56 millis  709,00 micros  186,85 millis 
   sys time   62,72 millis  163,00 micros   62,55 millis

Feel free to test it installing Gitnow from branch optimizations and share your speed numbers.

@joseluisq
Copy link
Owner

Few days ago I did rewrite the .gitnow parsing and now the slow startup is no issue anymore.
See release 2.7.0

@xigoi
Copy link
Author

xigoi commented Feb 20, 2021

Great, it seems to be good now :)

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

Successfully merging a pull request may close this issue.

2 participants