The plugin processing in ctools_entity_from_field_get_children is taking nearly 100 ms on a site, which is about 1/3 the page load of a page I am testing.

As far as I can tell, this information doesn't change between page loads so would be better to cache.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hefox’s picture

Status: Active » Needs review
FileSize
11.4 KB
B-Prod’s picture

FileSize
13.25 KB

The patch in #1 breaks the $context_types variable when retrieving from cache. This means that the plugins are not processed as expected in the last foreach loop, because the $context_types is an empty array.

So the expected 'required context' property is not set, giving errors (@see #2490514: Notice: Undefined index: required context in ctools_context_get_relevant_relationships() ... )

The patch below fixes that and tries to improve the performance, by not calling the "alter" hooks on the cached data, but before caching them, because those alterations does not change on a "per page" basis.

mpotter’s picture

I'm a bit confused on what actually fixes the problem. Seems like your patch also changes the cache to be per-cid instead of just one giant cache. Is that related to the bug or just something you did to improve memory usage.

Also, there is at least one coding issue on the line:

$context_types = $plugins = array();

This isn't done in the Drupal coding guidelines. It needs to be:

$context_types = array();
$plugins = array();

Will get hefox to review this in more depth

rivimey’s picture

I'm having problems applying this patch.

I'm starting from this this version of ctools:

; Information added by Drupal.org packaging script on 2015-03-18
version = "7.x-1.7"
core = "7.x"
project = "ctools"
datestamp = "1426696183"

with the following patches applied (as part of the OA 2.42 build):

The following patches have been applied to this project:
- http://www.drupal.org/files/issues/ctools-keyboard-trap-2280853-37.patch
- https://www.drupal.org/files/issues/views_content-ajax-1910608-29.patch
- https://www.drupal.org/files/issues/1901106-ctools-views_content-override-ajax-30.patch
- http://drupal.org/files/2023705-ctools-autosubmit-2_0.patch
- https://www.drupal.org/files/issues/2448989-ctools-frome_field_children-1.patch
- https://www.drupal.org/files/issues/ctools-fix_entity_view_hooks_invoked_twice-2422123-15.patch
- https://www.drupal.org/files/issues/ctools-more_than_one_comment_pager-2483415-1.patch
- https://www.drupal.org/files/issues/ctools_context_optional_always_empty-1032218-13.patch

This file was automatically generated by Drush Make (http://drupal.org/project/drush).

When I try patching I get:

$ cd contrib/ctools
$ patch -p1 <../../../../../ctools-cache-for-entity-from-field-plugin-2448989-2.patch
patching file ctools.module
Hunk #1 succeeded at 1046 with fuzz 2 (offset -19 lines).
patching file plugins/relationships/entity_from_field.inc
Hunk #1 FAILED at 33.
Hunk #2 succeeded at 151 with fuzz 2 (offset 12 lines).
1 out of 2 hunks FAILED -- saving rejects to file plugins/relationships/entity_from_field.inc.rej

The failed hunk forms the 'guts' of the new work so it's not looking good...

I have attached a patch file that updates entity_from_field.inc to the version in OA 2.42, and this is a summary of the ctools changes as a whole.

 /PATCHES.txt                                                |only
 ctools.module                                               |   28 +
 includes/context.inc                                        |    2
 includes/modal.inc                                          |    1
 js/auto-submit.js                                           |   26 -
 js/modal.js                                                 |  131 +++++
 page_manager/plugins/tasks/node_view.inc                    |   41 +
 plugins/content_types/node_context/node_comment_wrapper.inc |    3
 plugins/content_types/node_context/node_comments.inc        |    3
 plugins/relationships/entity_from_field.inc                 |  180 ++++---
 views_content/plugins/content_types/views_panes.inc         |  174 ++-----
 views_content/plugins/views/views_content..._panel_pane.inc |  234 +++++++++-
 views_content/views_content.module                          |   75 +++
 13 files changed, 666 insertions(+), 232 deletions(-)
mpotter’s picture

You need to "undo" the previous version of the patch first:

patch -p1 -R <../../../../../2448989-ctools-frome_field_children-1.patch
patch -p1 <../../../../../ctools-cache-for-entity-from-field-plugin-2448989-2.patch

(assuming you put the patch in #1 in the same place as the one from #2. The -R option on patch reverses a previously applied patch)

mpotter’s picture

Also, can you edit your comment #4 and hide the file you uploaded. It's confusing people because it looks like the updated full patch for this issue. There should be a checkbox when you edit the comment to not show the file in the file list.

DamienMcKenna’s picture

Maybe talk to dsnopek to see if this patch can be ran through the Panopoly test suite?

hefox’s picture

The new patch changes the alter hooks to be one per caching instead of per page load -- to me, that's outside the scope of a performance issue (unless it's specially part of the performance) as someone may be using that alter hook in a way that depends on context.

Altering first patch to also cache context_types variable so it won't be empty when using from cache, thanks for finding the bug.

mpotter’s picture

B-Prod: can you verify that the patch in #8 takes care of the issue for you?

mpotter’s picture

DamienMcKenna: The issue to update ctools in Panopoly is here: #2477363: Patches for ctools from OpenAtrium which should be getting tested by the Panopoly travis instance.

B-Prod’s picture

Patch in #8: yes, it fixes the issue. Missing the $plugins = array(); that initialize the variable, that could theoretically be necessary if there is not any field or not any bundle (very edge case).

Though, I do not understand why the "alter" hooks are not performed before caching the results. There is no contextual data that are passed to those hooks, so there is no need to process them on each page, instead of once before caching. Same toughs on the loop on the $context_types that make ever and ever the exact same things on each call... We want to use cache to improve the performances, so why keeping some extra process while caching some other ? Moreover, this would reduce the cached data size since the required contexts does not need to be cached.

rivimey’s picture

Hidden, sorry for confusion
Ps the hide is on the node edit, not comment edit, form.

hefox’s picture

@B-Prod The page /always/ has contextual data -- the path, the current space, the current user, etc. -- and there's no way to know how someone is using an alter hook.

mgifford’s picture

DamienMcKenna’s picture

Moving this to the v7.x-1.10 release plan.

DamienMcKenna’s picture

This didn't get added to 7.x-1.10.

Chris Matthews’s picture

The 4 year old patch in #8 to entity_from_field.inc applied cleanly to the latest ctools 7.x-1.x-dev and fixes this issue per the comment in #11, but it may need another review before RTBC.