currently, _drupal_bootstrap_full loads a boat-load of code. also, currently drupal7 is slower than drupal6.

no code yet, but i'm creating this issue to tackle loading less code during bootstrap, and shifting more of drupal towards lazy-loading code via the registry.

note, #325665: Cache registry lookups is an important piece of this, as it makes the registry behave as a true lazy-load system.

CommentFileSizeAuthor
#17 lazyload.patch64.28 KBAnonymous (not verified)
#12 lazyload.patch56.98 KBAnonymous (not verified)
#3 lazyload.patch26.55 KBAnonymous (not verified)

Comments

kbahey’s picture

Subscribe.

Anonymous’s picture

will post some code soonish now that #325665: Cache registry lookups is in.

Anonymous’s picture

Status: Active » Needs work
StatusFileSize
new26.55 KB

ok, 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:

foreach (module_list() as $module)) {
  // do something with a hook on each module

and replace with:

foreach (module_implements($hook) as $module)) {
  // do something with $hook on each module
catch’s picture

subscribing for benchmarks.

damien tournoud’s picture

It'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:

@@ -545,7 +555,9 @@ function locale_translate_seek_screen() 
  */
 function locale_translate_seek_form() {
   // Get all languages, except English
-  $languages = locale_language_list('name', TRUE);
+  if (drupal_function_exists('locale_language_list')) {
+    $languages = locale_language_list('name', TRUE);
+  }
   unset($languages['en']);
 
   // Present edit form preserving previous user settings

Ouch. What if drupal_function_exists('locale_language_list') returns FALSE?

I suggest postponing this until we have something like #332733.

Anonymous’s picture

@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.

Anonymous’s picture

Anonymous’s picture

Anonymous’s picture

i'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?

Crell’s picture

I 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. :-)

Anonymous’s picture

yay, 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.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new56.98 KB

attached 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_help to return immediately:

function menu_get_active_help() {
  return '';
  $output = '';

then run this from the drupal root:

justin@ubuntu:~/code/drupal/7/registry$ for module in `ls modules/*/*.module` ; do echo "watchdog('wtf_another_module_loaded', __FILE__);" >> $module ; done

click around and see what you get.

Status: Needs review » Needs work

The last submitted patch failed testing.

swentel’s picture

Status: Needs work » Needs review

Watch out for that command line snippet , it severely breaks your installation :)

Anonymous’s picture

Status: Needs review » Needs work

boo, hiss, not sure why the testbot is unhappy.

also, swentel pointed out in #drupal that the watchdog calls don't work, so:

justin@ubuntu:~/code/drupal/7/registry$ for module in `ls modules/*/*.module` ; do echo 'file_put_contents("/path/to/log/file", __FILE__ . "\n", FILE_APPEND);' >> $module ; done
swentel’s picture

Status: Needs work » Needs review
justin@ubuntu:~/code/drupal/7/registry$ for module in `ls modules/*/*.module` ; do echo "watchdog('another_load', __FILE__);" >> $module ; done

This 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.

Anonymous’s picture

StatusFileSize
new64.28 KB

updated 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.

Status: Needs review » Needs work

The last submitted patch failed testing.

Crell’s picture

I 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.

dmitrig01’s picture

Status: Needs work » Needs review
dries’s picture

I'm not a fan of the class constants either.

Anonymous’s picture

@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.

Crell’s picture

In 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.

Anonymous’s picture

Status: Needs review » Closed (won't fix)

closing 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.