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

Lazy loading without generating a map #8

Open
jk opened this issue Mar 27, 2012 · 2 comments
Open

Lazy loading without generating a map #8

jk opened this issue Mar 27, 2012 · 2 comments

Comments

@jk
Copy link
Contributor

jk commented Mar 27, 2012

I knew that this day would come: Generating a map of the whole API and all its classes is quite cumbersome and isn't a good decision when it comes down to performance. When you also don't have any cache at hand it gets pretty sluggish on every request.

My intention by opening this issue is a refactoring on that topic, so that the class facilitates an autoloader which only loads the class which matches the requested URL. So the first advantage would be that you don't need so much memory by loading any possible class into memory. And on the other side, you have the advantage that you don't have to generate the map for all classes. Just for the requested one and its methods/actions.

Using an autoloader will change the behavior of the RestServer class, so that it loads every class it's able to load. I suggest that there will be a mechanism which prevents certain classes from being autoloaded. Perhaps a class comment like:

/**
 * @noUse
 */
class DoNotLoadThisClass {}

I consider this as a draft, any opinions on that proposal?

@jacwright
Copy link
Owner

When I created RestServer I knew there would be performance downsides at some point. I think an autoloader is a good idea. With slight modifications you could put off the parsing of the url mappings to happen only if the baseUrl is matched. $server->addClass('UserAPI', '/users') would be stored but the class wouldn't be loaded or the map generated unless the URL started with '/users'.

I'm happy to merge in any decent solutions you come up with.

@jacwright
Copy link
Owner

Also, not sure if this project fits your needs, but https://github.com/Luracast/Restler is a fork from RestServer and has moved on quite a bit. Development is more active than RestServer.

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