Closed (fixed)
Project:
Autoload
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Jun 2010 at 19:40 UTC
Updated:
22 Sep 2010 at 00:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
Crell commentedThe main reason is that the logic to detect classes inside a file is non-trivial regexing. Non-trivial regexing scares me. :-) It's one of the reasons I never went there. (The other being that this module started as just a proof of concept and the hook was easier.)
That said, were we go to that route I would actually prefer to just go all the way. Scan all info files, look for a files array, drop the info hook, etc. That would definitely warrant a 2.x branch of the module.
I suppose I'm undecided here if it would be sufficiently stable.
Comment #2
mikeryanIt would certainly be convenient for me - I'm backporting the Migrate module, which is still getting plenty of active development (i.e., new classes added, old ones moved from file to file). Not to mention modules built on Migrate 2.0, which define their own subclasses of my classes, I would like to spare them implementing hook_autoload_info().
Assuming there are no qualms about stealing the non-trivial regexing etc. from Drupal 7:-), I'll give it a shot.
Thanks.
Comment #3
Crell commentedThinking about it, actually, we may still need the hook for 3rd party libraries. I'm actually working on a module right now that uses a 3rd party library via the libraries module. The files[] array wouldn't account for that. See: http://engineeredweb.com/blog/10/5/3-tips-using-external-libraries-drupal
Comment #5
mikeryanOK... An easy way to keep the hook and add the .info parsing would be to implement autoload_autoload_info() to do the parsing.
Looking at the D7 registry.inc, it doesn't look too hard to incorporate. But, one thing it does is maintain registry tables with timestamps, so it only needs to parse changed files - parsing all .info files on each cache clear would, I expect, be prohibitive with many modules enabled. So, there's a tradeoff here - do the brute-force full reparse (simple but slow), introduce the registry and registry_file tables (just use the D7 registry.inc with mimimal change), or let modules explicitly indicate they want to be scanned (simple but fast, presuming only a small proportion of the modules on a given installation use autoload).
What do you think? I'm leaning towards the full-fledged registry.inc at the moment...
Comment #6
mikeryanHere's a shot at going whole-hog... Minimally tested, but it did find the dbtng and Migration classes.
Comment #7
mikeryanForgot to set the status...
Comment #8
Crell commentedI'd like to get feedback from other module maintainers that depend on autoload. This introduces a lot of new moving parts, and given how late we are in the Drupal 6 lifecycle I am not yet convinced it's worth it.
Mike, can you scare up some dependent module maintainers so we can get input from them? :-)
Comment #9
mikeryanDropped a note for DBTNG at #818368: QueryPlaceholderInterface omitted from hook_autoload_info().
I've rerolled the patch against latest CVS, adding documentation to README.txt and bringing in this fix from D7: #797024: Moving a class between files can cause SQL errors on registry rebuild.
Comment #10
mikeryanHere's an alternative approach, so installations with no modules taking advantage of the files[] feature don't have the overhead of the registry - a separate module, tentatively named autoautoload (since it adds an additional layer of automation). It could be packaged with autoload itself, or if you prefer not to I can create a separate project for it.
Suggestions for a better name welcome...
Thanks.
Comment #11
mikeryanCrell, what do you think about packaging autoautoload (by whatever name) with autoload? Migrate 2.0 on Drupal 6 is now dependent on it, so if it's not going to be accepted into autoload I need to create a project for it.
Thanks.
Comment #12
mfer commented@mikeryan There is a problem with your approach in #10. If you have to load 50 classes in 50 different files you add 50 sql queries. This is not so good for performance. From an autoloading performance perspective it's a definite slow down.
To avoid this in D7 there is caching. You can see the details in http://api.drupal.org/api/function/_registry_check_code/7.
I do like the idea of auto-detecting classes. But, the performance hit needs to be worked out first.
Comment #13
dave reidWould very much support this approach. I'm working on backporting the latest SimpleTests from D7 back to contrib and things would be much easier if we could have the modules define their .test files in the .info files and be included automatically.
Comment #14
dave reidHere's a revised (simpler) version that basically backports D7's registry to the autoload namespace, including all the same caching that D7 does. We still support the legacy hook_autoload_info() but only to pass that information into the registry scanner. Using this implementation people wanting to include classes from libraries can also implement hook_autoload_registry_files_alter().
I'm almost wondering if this should be split off into a backported namespace of 'registry' but I'd rather coordinate with the existing project first rather than duplicate.
Comment #15
dave reidRevised patch fixing some small bugs during the backport that I discovered while integrating this with the SimpleTest backport for D6 - which improves performance.
Comment #16
mfer commentedI'm lazy... so... I WANT!!!!!
Comment #17
dave reidSo what say you Crell? +1 or -1? :)
Comment #18
Crell commentedI talked to Dave just now, and here's the low-down:
- This is definitely 2.x material, as it's essentially a total gut rewrite of the entire module. The support for hook_autoload() is kind of an afterthought for backward compatibility.
- The registry in D7 has been mostly rewritten since I last worked on it, and it's doing all kinds of screwy things with variable parameter types. I neither comprehend the code anymore nor do I support that architecture, and am therefore not willing to support it.
- Fortunately, Dave is. :-) Dave Reid has been added as a co-maintainer on autoload and will be making a 2.x branch for this code shortly. Because, you know, Dave doesn't have enough modules already.
I'll let him close this issue when the time is right.
Comment #19
dave reidHooray! Committed the backport to DRUPAL-6--2: http://drupal.org/cvs?commit=417548
Thanks for your help and input Crell!
Comment #20
mikeryanThat's great, thanks!