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

Implement "autoload warmers" so tab completion and PsySH commands work with all classes. #650

Open
bobthecow opened this issue Aug 15, 2020 · 9 comments

Comments

@bobthecow
Copy link
Owner

i imagine it would be an interface, and maybe a couple of implementations. one based on composer, that reads either configs or generated autoloaders, uses them to enumerate all possible classes. another could be symfony finder based, and walk the filesystem according to the finder rules.

in all cases, we probably just want them to emit a list of files which possibly / probably contain classes, then use php parser to parse the file and make sure (1) it's valid PHP and won't error, (2) it contains only class and function definitions at the top level, not things that probably have side effects.

Originally posted by @bobthecow in #539 (comment)

👆See that issue for more discussion.

@bobthecow bobthecow changed the title Implement "autoload warmers" so tab completion and PsySH commands work with all classes in the current project. Implement "autoload warmers" so tab completion and PsySH commands work with all classes. Aug 15, 2020
@GrahamCampbell
Copy link
Contributor

What about just using composer's optimised autoloading mechanism. That already produces class mappings for us.

@GrahamCampbell
Copy link
Contributor

Moreover, it means we don't need to care about the (auto)loading mech ism for classes. They need not be PSR-0/4, even (which means requiring the files could have side effects other than defining a class/interface/trait).

@bobthecow
Copy link
Owner Author

Because nobody uses the optimized autoloader in development?

image

This warning seems like a pretty good reason not to 😀

But if it's possible to dump the autoloader somewhere else, or just dump to memory once, on launching the shell, or something like that, it might work?

@GrahamCampbell
Copy link
Contributor

I mean, I use psysh in production all the time. ;)

@bobthecow
Copy link
Owner Author

Composer's ClassMapGenerator itself could be a good autoload warmer:

Screen Shot 2020-08-16 at 7 22 54 AM

That runs on PsySH's source in ~0.02s, which is fast enough to do once on every shell session and just store it in memory.

@bobthecow
Copy link
Owner Author

Adding a dependency on composer/composer just to get the ClassMapGenerator doubles the size of PsySH's vendor directory :-/

@GrahamCampbell
Copy link
Contributor

The problem with doing that is we could require files that are not meant to be required. That is just doing the "classmap" strategy, right?

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Aug 16, 2020

The best strategy, I think, is just do an optimised autoload dump, possibly to some temp location, to give us an accurate list of all the classes, defined by the autoloading strategies from people's composer.json files, and that of the dependencies?

@bobthecow
Copy link
Owner Author

playing with a hacked up version of this, i'm not convinced we want to pre-warm vendor. there's a lot of transitive dependencies in there that i don't want cluttering up my tab completion :P

so maybe we make it opt-in? prefix based? namespace based? there's a sweet spot somewhere in here, but i'm not sure it's "every class known to composer".

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

No branches or pull requests

2 participants