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

coala is quite slow when showing version #2344

Closed
Makman2 opened this issue Jun 14, 2016 · 9 comments
Closed

coala is quite slow when showing version #2344

Makman2 opened this issue Jun 14, 2016 · 9 comments

Comments

@Makman2
Copy link
Member

Makman2 commented Jun 14, 2016

This is because coala imports every bear and then runs the version command. This shouldn't happen^^

@gitmate-bot
Copy link
Collaborator

Thanks for reporting this issue!

Your aid is required, fellow coalaian. Help us triage and solving this issue!

CC @sils1297, @AbdealiJK

@adtac
Copy link
Member

adtac commented Jun 15, 2016

Related: --help is equally slow (or just try --some-random-invalid-arg)

@sils
Copy link
Member

sils commented Jun 15, 2016

@hypothesist wanna profile it? :)

@sils
Copy link
Member

sils commented Jun 15, 2016

oh why do we import all bears? :/

@adtac
Copy link
Member

adtac commented Jun 15, 2016

@sils1297 call graph?

@adtac
Copy link
Member

adtac commented Jun 15, 2016

http://i.imgur.com/DIThpaY.jpg collecting bears is 50%

@sils
Copy link
Member

sils commented Jul 13, 2016

HERE IS THE EVIL THING:

    inputs_group.add_argument(
        '-b', '--bears', nargs='+', metavar='NAME',
        help='names of bears to use').completer =\
        ChoicesCompleter(get_all_bears_names())

the reason why every coala invocation takes a second even if it's only showing version
it's the autocompletion!
which collects all bears...

@sils
Copy link
Member

sils commented Jul 13, 2016

And here's a ChoicesCompleter that works :)

class ChoicesCompleter(object):
    """
    This class is copied and adapted from
    https://github.com/kislyuk/argcomplete.
    """
    def __init__(self, choices):
        self._choices = None

        if callable(choices):
            self._load_choices = (lambda self:
                                  setattr(self, 'choices', choices()))
        else:
            self.choices = choices

    def __call__(self, prefix, **kwargs):
        return (c for c in self.choices if c.startswith(prefix))

    @property
    def choices(self):
        if self._choices is None:
            self._load_choices(self)

        return self._choices

    @choices.setter
    def choices(self, iterable):
        """
        Initialize the choices with items from the given iterable.

        This also normalizes them to neat strings.
        """
        self._choices = []
        for choice in iterable:
            if isinstance(choice, bytes):
                choice = choice.decode(sys_encoding)
            if not isinstance(choice, str):
                choice = str(choice)
            self._choices.append(choice)

see also kislyuk/argcomplete#137 which is upstream.

@sils
Copy link
Member

sils commented Jul 13, 2016

and the PR at kislyuk/argcomplete#138

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

No branches or pull requests

4 participants