Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2448989-ctools-from_field_children-8.patch | 11.54 KB | hefox |
#2 | ctools-cache-for-entity-from-field-plugin-2448989-2.patch | 13.25 KB | B-Prod |
Comments
Comment #1
hefox CreditAttribution: hefox commentedComment #2
B-Prod CreditAttribution: B-Prod commentedThe 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.
Comment #3
mpotter CreditAttribution: mpotter commentedI'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:
This isn't done in the Drupal coding guidelines. It needs to be:
Will get hefox to review this in more depth
Comment #4
rivimeyI'm having problems applying this patch.
I'm starting from this this version of ctools:
with the following patches applied (as part of the OA 2.42 build):
When I try patching I get:
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.
Comment #5
mpotter CreditAttribution: mpotter commentedYou 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)
Comment #6
mpotter CreditAttribution: mpotter commentedAlso, 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.
Comment #7
DamienMcKennaMaybe talk to dsnopek to see if this patch can be ran through the Panopoly test suite?
Comment #8
hefox CreditAttribution: hefox at Phase2 commentedThe 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.
Comment #9
mpotter CreditAttribution: mpotter commentedB-Prod: can you verify that the patch in #8 takes care of the issue for you?
Comment #10
mpotter CreditAttribution: mpotter commentedDamienMcKenna: 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.
Comment #11
B-Prod CreditAttribution: B-Prod commentedPatch 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.Comment #12
rivimeyHidden, sorry for confusion
Ps the hide is on the node edit, not comment edit, form.
Comment #13
hefox CreditAttribution: hefox at Phase2 commented@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.
Comment #14
mgiffordComment #15
DamienMcKennaMoving this to the v7.x-1.10 release plan.
Comment #16
DamienMcKennaThis didn't get added to 7.x-1.10.
Comment #17
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 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.