Dashboard is invoked on all pages.

I started to work on a patch, but...

...debug_backtracing through dashboard module I get the feeling that we need to retitle this issue "Region and block building + rendering eats our performance"...

Comments

sun’s picture

StatusFileSize
new4.02 KB

Contains my cufa() tweak from #615822: Benchmarking / profiling of D7 to be able to see those function calls in the first place.

sun’s picture

StatusFileSize
new1.3 KB
new1.3 KB
sun’s picture

Title: Dashboard eats our performance » Dashboard, and region and block building + rendering eats our performance
StatusFileSize
new1.3 KB
new1.3 KB
new5.03 KB

Yes, it IS the block building and rendering. This is just a start, but the whole thing needs to be revamped.

janusman’s picture

Confirming it's slightly faster with the patch... but just slightly.

ab -c1 -n100 -C [session cookie] http://localhost/admin/dashboard
unpatched: 6.69 req/sec
patched: 6.76 req/sec

moshe weitzman’s picture

Could you elaborate on the problem with block building and rendering? We don't usually have many blocks on a page so I would surprised if thats a significant contributor.

catch’s picture

I think when you look at a call graph, block rendering includes the rendering of the main content block, so that's probably what's showing up, but haven't looked into it much.

We are currently attempting to render the dashboard on every single page though, which is stupid.

@sun - can you re-roll without the call_user_func_array() changes?

David_Rothstein’s picture

We are currently attempting to render the dashboard on every single page though, which is stupid.

As far as I recall, we specifically make sure not to render it - see http://api.drupal.org/api/function/dashboard_block_info_alter/7

So I'm not sure I understand how this issue is about anything more than micro-optimization? (Not to say that it isn't worth doing, of course, but I don't understand how this would lead to major performance improvements.)

catch’s picture

StatusFileSize
new32.32 KB

Here's what shows up when viewing the front page.

sun’s picture

StatusFileSize
new2.49 KB

Without cufa() changes.

David_Rothstein’s picture

Looks about right to me.

What is the rationale for using static rather than drupal_static() here?

David_Rothstein’s picture

Title: Dashboard, and region and block building + rendering eats our performance » Dashboard, region and block building have unnecessary function calls
Priority: Critical » Normal

Much more accurate title and priority, IMO :)

sun’s picture

What's the rationale for using drupal_static?

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks!

David_Rothstein’s picture

Status: Fixed » Needs review
StatusFileSize
new672 bytes

Well, I thought the default policy was to use drupal_static() unless there is a really good reason not to... but the reality is that there is no policy :)

In any case, I think we do need it for dashboard_regions() since the results of that function come from module_invoke_all(), so it seems like they could change. Probably don't need it for dashboard_is_visible().

scroogie’s picture

I thought the policy is to use drupal_static only where you need to be able to reset the cache in special situations (those situations where a $reset parameter was formerly used). If you wouldn't have used a $reset parameter before, you wouldn't use a drupal_static now. So as sun noted, the question should always be: What's the rationale for using drupal_static? instead of the other way around.
About the module_invoke_all(). Can't this only change if a new module is activated? In that case it would be before dashboard_regions() is called for the first time, or not?

David_Rothstein’s picture

Well, module_enable() can be called at any time in a page request or while running a script, and we can't predict when that will be in relation to anything else...

sun’s picture

1) A script doesn't count, because you won't see a dashboard without a UI.

2) If you expect that module_enable() will have any effect within the same request... then you have strange expectations IMHO. Drupal's overall caching doesn't allow for that. Arbitrary results is all what you may get, depending on when during the request you invoke it. Even if you convert to a drupal_static here, who will reset this static when a module is enabled?

catch’s picture

Title: Dashboard, region and block building have unnecessary function calls » Use drupal_static() in dashboard_regions()
Priority: Normal » Minor
Issue tags: -Performance

No longer a performance issue.

David_Rothstein’s picture

The results of module_enable() definitely work correctly within the same page request. If they didn't, installing Drupal via the command line would not work..... And although it's true that you can't see the dashboard in a command line script, you still might want to query information about it.

In any case, there is now (voluminous) documentation at http://api.drupal.org/api/function/drupal_static/7 about when drupal_static() should and shouldn't be used, and although I think the whole drupal_static() thing is a bit weird to begin with, IMO that clearly indicates it should be used here. It's also a lot better than trying to document why it shouldn't be used, which is now done in a lot of places in core that intentionally skip use of drupal_static :)

Patch in #14 still applies....

casey’s picture

Status: Needs review » Reviewed & tested by the community

dashboard_regions()'s static variable does depend on information outside of the function and that might change during a single page request.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks!

David_Rothstein’s picture

Title: Use drupal_static() in dashboard_regions() » Dashboard, region and block building have unnecessary function calls
Priority: Minor » Normal

Back to original title and priority, for posterity.

Status: Fixed » Closed (fixed)

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