I haven't found a good reason to keep drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE) in init_theme. Maybe I'm missing something but the way the system is layed out DRUPAL_BOOTSTRAP_DATABASE is already executed before from the drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) in the index.php file. And the way drupal_bootstrap is constructed it loops and executes every phase until the requested phase has completed. So just because DRUPAL_BOOTSTRAP_DATABASE phase is being executed in theme.inc we execute DRUPAL_BOOTSTRAP_CONFIGURATION and DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE twice.

Patch attached.

CommentFileSizeAuthor
remove_drupal_bootstrap_from_init_theme.patch.txt486 bytesAnonymous (not verified)

Comments

Frando’s picture

Title: drupal_bootstrap in theme.inc causing too much overhead / resource use. » 2drupal_bootstrap in theme.inc causing too much overhead / resource use.
Priority: Normal » Minor

Nothing gets executed twice, as drupal_bootstrap is keeping a static array of bootstrap phases, and it will only execute phases that haven't been executed yet. So the overhead caused by this line is ridicolously minimal (think of one integer comparison).

So if we need to have bootstrapped drupal up until DRUPAL_BOOTSTRAP_DATABSE to init the the theme layer, why not call it?
It makes it possible to call init_theme from anywhere without having to worry about wether there is already a database connection available or not.

Frando’s picture

Title: 2drupal_bootstrap in theme.inc causing too much overhead / resource use. » drupal_bootstrap in theme.inc causing too much overhead / resource use.
Anonymous’s picture

Priority: Minor » Normal

The staticness of $phases is just to keep $phases from being initialized more than once. The code executes more than once from what I'm seeing.

function drupal_bootstrap($phase) {
  static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL);

  while (!is_null($current_phase = array_shift($phases))) {
    _drupal_bootstrap($current_phase);
    if ($phase == $current_phase) {
      return;
    }
  }
}

And _drupal_bootstrap doesn't prevent the duplicate execution of conf_init and neither does conf_init.

Please correct me.

Anonymous’s picture

Priority: Normal » Minor

I'm correcting myself: the array_shift causes the staticness of $phases to not loop through the arrays again.

RobRoy’s picture

@earnie - Feel free to mark won't fix or by design once an issue is cleared up like this so it keeps the issue queue clean.

Anonymous’s picture

I still think the patch needs applied. Each minuscule piece of irrelevant code speeds up the code by minuscule amounts. Leaving irrelevant code doesn't make since.

Anonymous’s picture

Title: drupal_bootstrap in theme.inc causing too much overhead / resource use. » drupal_bootstrap in theme.inc causing minuscule resource use.
RobRoy’s picture

Title: drupal_bootstrap in theme.inc causing minuscule resource use. » drupal_bootstrap in theme.inc causing too much overhead / resource use.
Status: Needs review » Closed (works as designed)

I think this line "It makes it possible to call init_theme from anywhere without having to worry about whether there is already a database connection available or not." means that it IS relevant. Marking by design, but feel free to re-open if you really want.

I think there are much better issues to focus on like this one: http://drupal.org/node/92630.