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. =)
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 2416451-10.patch | 1.38 KB | shubham.prakash |
| #8 | ctools-pm-cache_loaded_arguments-2416451-8.patch | 1.38 KB | maximpodorov |
Comments
Comment #1
kalistos commentedPatch adding cache for loaded arguments.
Comment #2
maximpodorov commentedCool!
Comment #3
kalistos commentedComment #4
andypostthen you need a way (api call) to unset this
Comment #6
kalistos commentedIn 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.
Comment #7
kalistos commentedOr second way, we can add new incoming variable $reset, which is false by default.
Comment #8
maximpodorov commentedI modified the patch to conform the rules of patch files. #4 issue is not solved.
Comment #9
chris matthews commentedThe 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.
Comment #10
shubham.prakash commentedRerolled from #8
Comment #11
japerryDrupal 7 is no longer supported, closing.