danhper / fundle

A minimalist package manager for fish shell
MIT License
375 stars 22 forks source link

With several plugins, it's quite slow to start up #38

Closed BarbzYHOOL closed 5 years ago

BarbzYHOOL commented 6 years ago

I think with fisherman and omf it is not as slow as fundle. However I really like fundle atm, simpler, easier to install and one nice plugin (fastdir).

Any idea how to make it quicker?

danhper commented 6 years ago

I know fisherman is fast because it uses a flat directory structure, avoiding the need to add things to the path at each shell startup. For omf, I am not sure. I use less than 10 plugins so speed has never really been an issue for me, but startup time definitely increases with the number of plugins. Do you have some plugins in particular taking a long time to load? fundle sources all the files in the top directory if no init.fish is found, so this could be one of the reasons. Depending on what is taking time, let's see if we can come up with something.

BarbzYHOOL commented 6 years ago

It takes like 2-3seconds to reload (a bit annoying when doing tests)

__fundle_load_plugin tuvistavie/fish-fastdir . /home/user/.config/fish/fundle 1: 68694us
__fundle_load_plugin edc/bass . /home/user/.config/fish/fundle 1: 59512us
__fundle_load_plugin fisherman/git_util . /home/user/.config/fish/fundle 1: 64458us
__fundle_load_plugin fisherman/z . /home/user/.config/fish/fundle 1: 75752us
__fundle_load_plugin fisherman/humanize_duration . /home/user/.config/fish/fundle 1: 57518us
__fundle_load_plugin fisherman/transfer . /home/user/.config/fish/fundle 1: 56737us
__fundle_load_plugin fisherman/gitignore . /home/user/.config/fish/fundle 1: 56979us
__fundle_load_plugin fisherman/get_file_age . /home/user/.config/fish/fundle 1: 55041us
__fundle_load_plugin yuki777/git_porcelain . /home/user/.config/fish/fundle 1: 60026us
__fundle_load_plugin fisherman/tio . /home/user/.config/fish/fundle 1: 58460us
__fundle_load_plugin BarbzYHOOL/plugin-bak . /home/user/.config/fish/fundle 1: 54164us
__fundle_load_plugin oh-my-fish/plugin-basename-compat . /home/user/.config/fish/fundle 1: 63574us
__fundle_load_plugin oh-my-fish/plugin-pbcopy . /home/user/.config/fish/fundle 1: 63408us
__fundle_load_plugin oh-my-fish/plugin-gityaw . /home/user/.config/fish/fundle 1: 64616us
__fundle_load_plugin oh-my-fish/plugin-foreign-env . /home/user/.config/fish/fundle 1: 65134us
__fundle_load_plugin oh-my-fish/plugin-dpaste . /home/user/.config/fish/fundle 1: 85576us
__fundle_load_plugin oh-my-fish/plugin-jump . /home/user/.config/fish/fundle 1: 59893us
__fundle_load_plugin oh-my-fish/plugin-argu . /home/user/.config/fish/fundle 1: 66941us
__fundle_load_plugin BarbzYHOOL/plugin-msg . /home/user/.config/fish/fundle 1: 74567us
__fundle_load_plugin oh-my-fish/plugin-sudope . /home/user/.config/fish/fundle 1: 58259us

And I will probably add like 5 more plugins lol

faho commented 5 years ago

So, I've looked into this a bit, and there are a bunch of easy fixes to add, especially if you're okay with depending on fish 2.3.0 (which was released in 2016).

Mainly, as always in shell scripts, these involve replacing external commands with builtins.

E.g:

which is used a few times, but should be replaced with command -s.

if not which git > /dev/null 2>&1

should be

if not command -s git >/dev/null 2>&1

(or command -sq, which was introduced in fish 2.5)

Most sed, grep and awk invocations can be replaced with the string builtin, which especially for small strings is much faster.

E.g.

set -l plugin_dir (echo "$fundle_dir/$plugin/$path" | sed -e 's|/.$||')

should be replaced with

set -l plugin_dir (string replace -r '/.$' '' -- "$fundle_dir/$plugin/$path")

I've gotten the time to load 16 random plugins down from 300ms to 75ms (of which at least 25ms is spent in the plugins themselves).

danhper commented 5 years ago

@faho Thank you very much! Is there any chance you could send a PR with your improvements please? It's ok to drop 2.2, people using an old version of fish will just have a slower startup, that's not a big deal. I'll maybe add a check in the self-update function.