Closed (won't fix)
Project:
Drupal core
Version:
7.x-dev
Component:
base system
Priority:
Critical
Category:
Task
Reporter:
Anonymous (not verified)
Created:
9 Nov 2008 at 06:26 UTC
Updated:
21 Sep 2021 at 20:41 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kbahey commentedSubscribe.
Comment #2
Anonymous (not verified) commentedwill post some code soonish now that #325665: Cache registry lookups is in.
Comment #3
Anonymous (not verified) commentedok, here goes.
this is a kitten-killer right now, and not much of a looker either.
posting anyway, so chx can have a look at it.
one thing that this patch needs is contants defined by classes. right now, there's some ugly
if (!defined('foo'))stuff.if we have
my_module::MY_CONSTANT, lazy loading via the registry will Just Work, which is nice. that will be separate patch very soon. if that lands, then this lazy loading idea really could happen without too much ugly.also, #333143: bootstrap modules begone would make this patch less of a kitten killer, as would a patch to get rid of the remaining places where we use:
and replace with:
Comment #4
catchsubscribing for benchmarks.
Comment #5
damien tournoud commentedIt's a good battle to fight that Drupal load less code. But... that implementation is just ugly.
Please implement #332733: Implement a way to require that some functions are available before adding ugliness such as:
Ouch. What if
drupal_function_exists('locale_language_list')returns FALSE?I suggest postponing this until we have something like #332733.
Comment #6
Anonymous (not verified) commented@Damien: yes, i think that's a good idea, and along with the other kitten-saving patches mentioned, will help to make this less ugly.
my intention with the first patch was just to get the tests to pass, see how ugly it looks and how we could break it up.
Comment #7
Anonymous (not verified) commentedjust noting that i've created #334024: Use const keyword to define constants instead of define().
Comment #8
Anonymous (not verified) commentedjust noting that i've created #334030: replace module_list with module_implements when calling a hook.
Comment #9
Anonymous (not verified) commentedi'll update this patch in a day or two now that the module_list --> module_implements patch is in.
any comments on the contants in classes patch?
Comment #10
Crell commentedI don't think we can realistically get rid of bootstrapping all .module files. There's too many functions that are called directly for which module_invoke('node', 'load', arg(1)) is just plain silly. Instead, we should work to make .module files as small as possible. That means anything that is called dynamically (eg, hooks) needs to be elsewhere. That makes the constant-in-class question moot.
The alternative is to expand on #329026: Differentiate between cacheable and non-cacheable registry files. Instead of 2 classes of file, we have 3: always pre-load, load-but-cache, and never-cache. Constants, node_load(), etc. would go in "some file" in that first category. Most hooks go in the second. Registry hooks go in the third.
That still allows module authors to organize their code however they like, but smart ones can optimize by cut and paste and tweaking their info file. .module then ceases to be magical, and is probably not even necessary in the first place. We can force-load the code we need to and lazy-load the rest.
The DX would probably be cleaner if we could use XML attributes rather than nested ini-arrays, but that's a whole other battle I'm not going to fight right now. :-)
Comment #11
Anonymous (not verified) commentedyay, more kittens - #287178: Use hook_form_FORM_ID_alter() where possible.
i'll work on that patch, because in reviving this one, i noticed that our hook_form_alter implementations load too much code, too much of the time.
Comment #12
Anonymous (not verified) commentedattached patch is updated for HEAD, and is a tiny bit less ugly after some of the kitten-saving patches landed.
also, rolled in the comment constants in a class as per #334024: Use const keyword to define constants instead of define() - can't really see that going in separate from this patch.
still not ready by any means, but don't want to let it drift too far, and setting to code needs review to get eyes on it. all tests pass.
for those who want to look at areas where drupal loads lots of code for no good reason, a) patch
menu_get_active_helpto return immediately:then run this from the drupal root:
click around and see what you get.
Comment #14
swentel commentedWatch out for that command line snippet , it severely breaks your installation :)
Comment #15
Anonymous (not verified) commentedboo, hiss, not sure why the testbot is unhappy.
also, swentel pointed out in #drupal that the watchdog calls don't work, so:
Comment #16
swentel commentedThis will work also, the string was originally too long to get inserted into the database.
Edit:: Do not enable syslog.module, this also breaks things.
Comment #17
Anonymous (not verified) commentedupdated patch to keep up with HEAD.
also, converted comment.module and profile.module constants to class constants.
all tests pass, except from "Menu item creation/deletion", but that's failing on HEAD anyway.
Comment #19
Crell commentedI am still -1 on the class constants. I don't see what the value is here, when we can't reasonably get rid of .module files yet anyway.
Comment #20
dmitrig01 commentedComment #21
dries commentedI'm not a fan of the class constants either.
Comment #22
Anonymous (not verified) commented@Dries and Crell: i'm not a huge fan either, but we need some way to make constants lazy-load if we are going to move away from just loading all enabled modules.
so, either we find another way to make them available, or we give up on lazy-loading .module files.
i'm happy enough to drop this if noone else thinks its a good idea. getting a working implementation has uncovered some useful patches, so its been worth it i think.
@Crell: if you can flesh out your 'lets use the registry to load less code ideas' further by creating an issue/blog entry/dev list post, i'm happy to work with you on the implementation.
Comment #23
Crell commentedIn short: Follow the link I posted in #10 above. Now instead of 2 keys have 3: always, cache, and nocache. Files marked "always" will always be loaded on every (uncached?) page if that module is enabled. Files marked "cache" will be lazy-loaded and then front-loaded on future requests. This is what happens to all files right now. Files marked "nocache" will be lazy-loaded but NOT front-loaded. That's for things like the file where hook_menu lives, since there's no reason to always use it.
Simple, effective, puts the work on the programmer to know his own module (which he will better than Drupal can), and removes any magic meaning from .module files. A module can then be all lazy-load or no lazy-load or a mix, depending on what makes sense for it. And degenerate case, authors throw everything into a .module file, put in one line in their info file, and the code all still works. That keeps the barrier to entry low.
Comment #24
Anonymous (not verified) commentedclosing this issue after a discussion with Crell and webchick in #drupal.
will continue the "lets load less code" battle here at #340723: Make modules and installation profiles only require .info.yml files.