How do you get down to the lowest bootstrap level using the least amount of includes and dependencies? Do you have any coding tricks that reduce the need for higher bootstraps and includes/dependencies? I like to use entity_metadata_wrapper, but perhaps shouldn't for js related code? I also have several entityreferences and taxonomy terms in use -- does this simply require you use DRUPAL_BOOTSTRAP_LANGUAGE?

I basically figured out what to include/depend on by bouncing through the errors, search for the function in the codebase to either include or depend. Any recipes for this type of thing?

For example, I am trying to display a login form, but I have to boot all of the way to DRUPAL_BOOTSTRAP_LANGUAGE. Here is some relevant code. Firs the hook_js item:

'user_login' => array(
  'callback' => 'anglestrap_user_login',
  'includes' => array('form', 'ajax', 'menu', 'lock', 'path', 'errors'),
  'dependencies' => array('user', 'ctools', 'devel', 'field', 'entity', 'variable'),
  'file'         => 'user_login.form.inc',
  'bootstrap'    => DRUPAL_BOOTSTRAP_LANGUAGE,
  //'access arguments' => array('e.g. permission'),
  'access callback'  => 'anglestrap_user_is_not_logged_in',
),

And the callback:

function anglestrap_user_login() {
  $form = drupal_get_form('user_login');
  $messages = drupal_get_messages();
  return array('form' => $form, 'messages' => $messages);
}

Comments

michielnugter’s picture

Status: Active » Fixed

Hi RobKoberg,

I pretty much exactly follow the same path as me in figuring out which dependencies, includes and bootstrap is required for a JS callback, no better recipe here.

The bootstrap level is dependent on what your expecting from the returned result. If you can live without translations, bootstrap to a lower level. Mostly, if you need to bootstrap to a higher level than standard (database) you'll need to think hard about if using this module is worth it (I'm not saying it's not, but the gains start to decrease fast).

About the entity_metadata_wrapper. It's an excellent tool and very useful in normal situations. Do keep in mind that these constructs cost performance to use and with the JS module you're trying to maximize performance. The JS module can only help you a little, your own code can have far more impact on performance than the JS module can save.

BTW: I use the JS module frequently for entityreference fields, it's a great way of making uncached requests a lot more responsive and as I don't need translations in that project the bootstrap can stay quite low..

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

markhalliwell’s picture

Title: bootstrap level, includes and dependencies - best practices? » Developer discovery of includes and module dependencies
Version: 7.x-1.x-dev » 7.x-2.x-dev
Component: Documentation » Miscellaneous
Category: Support request » Feature request
Status: Closed (fixed) » Active

I too follow the same process. However, I would be very interested in seeing if there were a better way to enter some sort of "discovery" process, similar to how XHProf does it or even possibly just using it somehow. Then we could determine which functions are actually called from start to finish of a request and extrapolate the necessary includes/module dependencies from that.

Granted, this is obviously no easy task, however I'd like to keep this open as a reminder for a rainy day.

randallknutson’s picture

I'd be curious if this were discoverable programmatically. One way might be having the bootstrap at full the first time and recording all the files that were included and used and then caching that somewhere for subsequent requests. I'm not 100% sure this is possible but it would be worth looking in to.

markhalliwell’s picture

Title: Developer discovery of includes and module dependencies » Utilize XHProf (if available) to show functions/methods used in a callback

I really don't think there's any "automatic" way of determining which modules or includes are being used. The best we can really do is utilize XHProf (if it's installed) to capture the functions/methods being used in a given callback. Then it's up to the developer to determine where those come from and reduce the bootstrap and add the necessary modules/include dependencies.

  • markcarver committed a9c97f0 on 7.x-2.x
    Issue #2153317 by markcarver, RobKoberg: Utilize XHProf (if available)...
markhalliwell’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.