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

Trying rule missing_space_before_subcommand taking so long #1120

Closed
auspic7 opened this issue Jul 22, 2020 · 5 comments
Closed

Trying rule missing_space_before_subcommand taking so long #1120

auspic7 opened this issue Jul 22, 2020 · 5 comments

Comments

@auspic7
Copy link

auspic7 commented Jul 22, 2020

The output of thefuck --version (something like The Fuck 3.1 using Python 3.5.0 and Bash 4.4.12(1)-release):

The Fuck 3.29 using Python 3.8.2 and ZSH 5.8

Your system (Debian 7, ArchLinux, Windows, etc.):

ubuntu 20.04 on wsl2

How to reproduce the bug:

env THEFUCK_DEBUG=true thefuck test

The output of The Fuck with THEFUCK_DEBUG=true exported (typically execute export THEFUCK_DEBUG=true in your shell before The Fuck):

DEBUG: Trying rule: missing_space_before_subcommand; took: 0:00:08.341279
No fucks given

Anything else you think is relevant:

I have no idea why this taking so long. anyone else having this problem?

@dvjn
Copy link
Contributor

dvjn commented Oct 1, 2020

This rule is using get_all_executables in which it scans all the directories in PATH for possible executables AFAIK, normally it shouldn't be a problem, but in WSL the path of your host Windows OS gets concatenated with the Ubuntu's path. So it has to scan more paths for executable (to find the correct one), hence it takes longer.

Could you try out running and timing a non-existent command, and check if that takes a long time to execute too?
Something like:

$ time abcd

@auspic7
Copy link
Author

auspic7 commented Oct 2, 2020

$ time abcd 
zsh: command not found: abcd
abcd  0.00s user 0.01s system 18% cpu 0.049 total

non-existent command won't take a long time.

by the way, env THEFUCK_DEBUG=true thefuck abcd will still take longer time since Trying rule: no_command takes a lot.

DEBUG: Trying rule: no_command; took: 0:00:08.681820

@dvjn
Copy link
Contributor

dvjn commented Oct 4, 2020

I was not able to find a proper reason as to is why this happening. I think thefuck is just unoptimized at many places which are aggregating to make it slow.

I think, let's try a cProfile

THEFUCK_DEBUG=true python -m cProfile $(which thefuck) zzzzzz

@pdavies
Copy link

pdavies commented Jun 2, 2021

I think this might be a dupe of #1036. On WSL, usually no_command runs slowly for me, but I'm sure while testing that, once or twice I saw missing_space_before_subcommand running slowly instead. At a guess, memoization of get_all_executables means that whoever hits it first pays the performance penalty, and occasionally missing_space_before_subcommand gets there first.

The fix, as with #1036 currently, is to set excluded_search_path_prefixes. In my testing, /mnt/c/WINDOWS (and subdirectories) was overwhelmingly the culprit. Adding that has resulted in a massive speedup.

@scorphus
Copy link
Collaborator

Duplicate of #1036

@scorphus scorphus marked this as a duplicate of #1036 Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants