Within the menu system alone there are multiple calls to _menu_load_objects. On one of the config pages for domains it's called 8 times, and every time it calls domain_load. That would be fine except domain_load is not caching any call.

When I test the domain_lookup function, it calls the db every time. This is definitely going to be a performance drag, especially considering it calls hook_domain_load every single time as well.

Wouldn't it be better to just keep a default $reset = FALSE for domain_load?

function domain_load($domain_id = NULL, $reset = FALSE) {
  $domain = domain_lookup($domain_id, NULL, TRUE);
  if ($domain == -1) {
    return FALSE;
  }
  else {
    return $domain;
  }
}

Comments

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

With reports like this, please say exactly what page(s) you are referring to.

Then we need benchmarks. As a general rule, the domain_load() function should only be called by the menu router, and caching the result makes no sense, because it should be loading each domain one time.

agentrickard’s picture

I just did a quick scan through the code. There are two instances where domain_load() should be replaced with a cached domain_lookup().

domain_source_lookup()
domain_theme_form_alter()

In all other cases, it is used because we cannot load a cached data set.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1022 bytes

I found a version of this in the wild. We need this patch. domain_load() should only be used internally.

agentrickard’s picture

Priority: Normal » Critical

Bumping priority.

asherry’s picture

Sorry I didn't specify a page, I was mainly talking about a url like the theme admin page:
admin/structure/domain/view/[domain_id]/theme

In this case the menu router calls _menu_load_objects around 8 times. I noticed this problem because it then calls domain_api every time, and runs hook_domain_load multiple times on the same domain, which is odd.

With node_load, since it uses the entity controller, it runs once per actual node nid, then you know that hook_node_load will also run once for a particular node. It seems like domain_load should run once per domain, and then read from cache if the domain has already been loaded - like what the default entity controller does.

asherry’s picture

I'm also really concerned that domain_domains runs on most pages. I'm developing a site now that will have from 50 - 100 domains, and it will kill performance to run domain_lookup on all 50 on each domain request.

Any thoughts? I can spend some time on this, and domain_load itself, I just will need some context.

agentrickard’s picture

Does the patch in #3 help? Please review.

agentrickard’s picture

StatusFileSize
new2.96 KB

Here's another version that also removes the domain_domains() call for node lookups.

agentrickard’s picture

Metrics for the patch, btw, from a live site. Top is "before patch".

http://imgur.com/a/Lu1tb

agentrickard’s picture

StatusFileSize
new6.79 KB

Alright, here's a version that rips out much of the excess loading, and also removes the bad module_implements() reset that causes so much pain.

Needs some testers! Does this break anything?

agentrickard’s picture

StatusFileSize
new8.51 KB

The previous patch only worked if any module implementing hook_domain_load() also implemented hook_boot() or hook_domain_bootstrap_load().

The solution is to prevent modules from calling domain_lookup() too soon in the bootstrap cycle. This patch should be ready to go.

asherry’s picture

That looks good to me, I was testing with adding a hook_domain_load in the domain_theme module and now it only loads it for the appropriate domains - no duplicates.

I do notice though that on the domain list page it runs the domain_api multiple times for the default domain. I wonder if we could change line 1568 to
domain_default(TRUE, FALSE);
It doesn't seem like we need to run the api again if it's already statically cached?

That's so much for this patch.

~Alan~

agentrickard’s picture

StatusFileSize
new8.92 KB

Nice catch.

asherry’s picture

This works great for me now. I tried out our client's site with 2 domains, and then with 45 domains and didn't notice any difference in load time for pages only pertaining to the current domain.

agentrickard’s picture

Status: Needs review » Fixed

Committed!

   a5dc128..b4102e5  7.x-3.x -> 7.x-3.x

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

fixed the code and typo