Arguments loaded on pages created by PageManager in function pm_arg_load() multiple times. It called by _menu_translate() function (_menu_translate() -> _menu_load_objects() -> call_user_func_array() -> pm_arg_load()), and _menu_translate() is called multiple times with the same arguments.

First time it loadings at bootstrap from menu_get_item() when system detect current menu router (menu_get_item() -> _menu_translate()).
Second time in template_preprocess_page() when build tabs (template_preprocess_page() -> menu_local_actions() -> menu_local_tasks() -> _menu_translate()).
And another case, someone can use it directly to get loaded context.

Next, every time pm_arg_load() is calling it builds full context with full content renderable array with all elements and forms, and load all needed entities. And It can take a long time if form is big and have field_collections, entities and inner forms. In my case building context takes 2 seconds (a lot of entity references, a lot of field_collections, which have own entity references and own inner field_collections, which ... etc). So it's reasonable to build it one times only, but it build second time when trying access to all tabs. One more: it make full build context of my heavy form for checking access to tabs only!

I dont think that is ctools (or page_manager) module's fault. Need to optimize _menu_translate(), but we can smooth this bug by applaying cache loaded arguments. It seems that it unnecessarily to build context more then 1 time, so at second loading we can return context builded before, so we can use static cache. Unlikely access rights would change during building page.

I created patch, which add cache for loaded arguments and my pages are loading two times faster!

P.S. I know, my English not so good. =)

Comments

kalistos’s picture

Patch adding cache for loaded arguments.

maximpodorov’s picture

Cool!

kalistos’s picture

Issue summary: View changes
andypost’s picture

Category: Bug report » Task
Status: Active » Needs review
+++ b/sites/all/modules/ctools/page_manager/plugins/tasks/page.inc
@@ -527,19 +527,30 @@ function page_manager_page_get_named_arguments($path) {
+  $loaded_args = &drupal_static(__FUNCTION__, array());

then you need a way (api call) to unset this

Status: Needs review » Needs work

The last submitted patch, 1: ctools-pm-cache_loaded_arguments-2416451-1.patch, failed testing.

kalistos’s picture

In castom case you can use something like this:

function my_module_my_func($my_arg) {
$loaded_args = &drupal_static('_pm_arg_load', array());
if (isset($loaded_args[$my_arg])) {
unset($loaded_args[$my_arg]);
}
}

Api call may be like this function.

kalistos’s picture

Or second way, we can add new incoming variable $reset, which is false by default.

maximpodorov’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

I modified the patch to conform the rules of patch files. #4 issue is not solved.

chris matthews’s picture

Assigned: kalistos » Unassigned
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old patch in #8 to page.inc does not apply to the latest ctools 7.x-1.x-dev and if still applicable needs to be re-rolled.

Checking patch page_manager/plugins/tasks/page.inc...
Hunk #1 succeeded at 526 (offset -1 lines).
error: while searching for:
  $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value);

  // convert false equivalents to false.
  return $context ? $context : FALSE;
}

/**

error: patch failed: page_manager/plugins/tasks/page.inc:548
error: page_manager/plugins/tasks/page.inc: patch does not apply
shubham.prakash’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Rerolled from #8

japerry’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.