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

Tab completion slow #340

Open
andyneff opened this issue Feb 10, 2021 · 1 comment
Open

Tab completion slow #340

andyneff opened this issue Feb 10, 2021 · 1 comment

Comments

@andyneff
Copy link
Member

andyneff commented Feb 10, 2021

Problem

Tab completion is getting really slow on projects of decent size. I was able to track it down to the _just_load_justfile call. This is where everything is loaded so that plugins can be discovered, and parsed. The timing for this call can be emulated via:

$ time bash -ic ". setup.env; . external/vsi_common/linux/source_once.bsh; _just_load_justfile Justfile"

real    0m4.014s
user    0m2.723s
sys     0m1.296s

This is because, source_once is disabled (by design) in interactive mode:

$ time bash -c ". setup.env; . external/vsi_common/linux/source_once.bsh; _just_load_justfile Justfile"

real    0m0.316s
user    0m0.220s
sys     0m0.105s

Possible Solutions:

  1. Add an additional flag, so that tab complete can run in a subshell, and go ahead and use source_once
if [[ $- != *i* -o ${JUST_SOURCE_ONCE} = 0 ]]; then
  source_once &> /dev/null && return 0
fi
  1. Come up with a new way to discover plugins. Forcing the use of JUST_PLUGIN_FILE could work here, but would involve multiple steps of refactoring:
    1. Add a check into all plugins, that error out if they aren't being sourced from _just_get_plugins (a simple check gate for a private variable would be good enough)
    2. All projects would need to be updated to use this
    3. Dev would have to get used to this

Option 2 does have the advantage that potentially even faster tab completion could be accomplished, eventually on windows too.

Ideas? @scott-vsi @drewgilliam

@andyneff
Copy link
Member Author

  1. After option 1, adjust tab complete to cache the complete options.
    • The first time tab complete is run
      1. Load the justfile like normal
      2. Parse the files and store the results in an array (that stays in the main bashes memory scope, or worse write to a cache file in the repo that is .gitignored)
      3. Use the list of JUST_HELP_FILES to know which files to monitor.
    • subsequent times tab is pressed
      1. Check the time and/or size? of the files (via stat), and if any of the files changed, rerun "first time tab completion"
      2. If no files changes, just use the cached values, this should be much faster on subsequent runs

Windows Timing

$ time bash -c ". setup.env; . external/vsi_common/linux/source_once.bsh; _just_load_justfile Justfile"

real    0m2.465s
user    0m0.627s
sys     0m1.617s

$ time bash -ic ". setup.env; . external/vsi_common/linux/source_once.bsh; _just_load_justfile Justfile"

real    0m6.717s
user    0m3.004s
sys     0m3.105s

Even when the source once issue is fixed, it's too slow in windows.

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

1 participant