New thread for discussing how to optimize parts of URLResolver for speed improvements on slower-CPU devices like the RPi.
Since I'm using a Raspberry Pi as my XBMC host, my biggest bottleneck for this plugin is CPU time. I've been looking through the code trying to figure out how to speed up the listing of available streams once an episode is selected. It looks like the most expensive part CPU-wise is finding which resolver to use for each source (_find_resolvers() in types.py). I was looking at a couple different ways of speeding this up. I figured I'd mention them here and see if this was something you were interested in. If it is, I can work on modifying the way URLResolvers work to speed up the whole process. If not, I'll just hack at it on my Pi so it's faster for me.
Option 1: Return the first working resolver
Right now, _find_resolvers check .valid_url on every installed resolver, and then returns a list of valid ones. However, the rest of the code just takes the first resolver in this list and uses it. The easiest/hackiest way to speed things up would be to immediately return once a valid resolver is found, instead of looking for all valid ones. This isn't the greatest idea because you may want to change the code in the future to cycle through all valid resolvers if one fails, instead of just using the first one in the list.
Option 2: Flip the loop
Instead of looping over sources and then checking them against each resolver, loop over resolvers and check them against all the sources. The benefit here is that you could compile the regex matches in each valid_url call, which might help a bit. I know python will cache the last couple regex matchers, but since there are a whole bunch of resolvers, I think it's being forced to recompile the regex matcher for each source. Not sure how much of a difference compiled regex speed makes, but it might help.
Option 3: Change how Resolvers are loaded
This would be a much larger code change. Basically, the section where you register the available resolver plugins would pull an attribute from each resolver that contains a regex pattern to match for that resolver. For _find_resolvers, instead of having to init and call a regex function from each resolver, you would have a dictionary or list of tuples of precompiled regex patterns and the name of the resolver they are for. I think this way is the most work, but might substantially speed of the _find_resolvers call... or I'm entirely wrong and it won't do much at all.
If any of these sound like they'd be worth doing, let me know and I'll take a stab at adding them to my fork. If not, I'll just try a couple things to speed up my Pi.
Thanks!
I think this is worth a good discussion, especially with XBMC being ported to so many small devices and how hugely popular RPi is.. I'm always in to optimizing our code!
Can you fire up a new dedicated thread where we can chat about it?