Problem/Motivation

We suspect that Cache::mergeContexts(), Cache::mergeTags() and Cache::mergeMaxAges() can be optimized by no longer supporting N arguments (using func_get_args()), but instead only accepting 2 arguments (which is the most common case) and then optimizing for that.

Proposed resolution

Optimize for 2 arguments.

Profiling: see #9.

Remaining tasks

None.

User interface changes

None.

API changes

Yes: Cache::mergeTags, Cache::mergeContexts and Cache::mergeMaxAges now all only support 2 arguments instead of the previously supported n arguments.

Data model changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it optimizes performance in a very, very hot code path.
Issue priority Major because it has a significant performance impact.
Prioritized changes The main goal of this issue is performance
Disruption Minimally disruptive for core/contributed and custom modules because 99% of the time, the functions are called with 2 parameters. However, any places where these functions are called with >2 parameters, they will need to be updated.
CommentFileSizeAuthor
#73 optimize-2471232-73.patch25.93 KBborisson_
#73 interdiff.txt3.07 KBborisson_
#69 interdiff.txt1.64 KBborisson_
#69 optimize-2471232-68.patch25.91 KBborisson_
#65 optimize-2471232-65.patch24.27 KBborisson_
#65 interdiff.txt1.28 KBborisson_
#63 optimize-2471232-63.patch24.21 KBborisson_
#63 interdiff.txt10.95 KBborisson_
#60 optimize-2471232-60.patch21.69 KBborisson_
#60 interdiff.txt4.12 KBborisson_
#58 interdiff-2471232-54-57.txt1.5 KBJeroenT
#57 optimize-2471232-57.patch21.48 KBJeroenT
#57 interdiff-2471232-54-57.patch1.5 KBJeroenT
#54 optimize-2471232-54.patch21.56 KBborisson_
#54 interdiff.txt7.75 KBborisson_
#49 optimize-2471232-49.patch19.98 KBborisson_
#49 interdiff.txt14.4 KBborisson_
#45 optimize-2471232-44-final.patch20.7 KBsorressean
#44 interdiff.txt1.81 KBsorressean
#44 optimize-2471232-44.patch0 bytessorressean
#40 optimize-2471232-40.patch20.7 KBsorressean
#40 interdiff.txt14.48 KBsorressean
#39 optimize-2471232-39.patch18.96 KBborisson_
#39 interdiff.txt1.08 KBborisson_
#37 optimize-2471232-37.patch18.24 KBborisson_
#37 interdiff.txt2.14 KBborisson_
#35 optimize-2471232-35.patch16.47 KBborisson_
#33 interdiff-2471232-30-33.txt5.04 MBruha
#33 optimize-2471232-33.patch16.47 KBruha
#30 optimize-2471232-30.patch16.54 KBJeroenT
#30 interdiff-2471232-27-30.txt584 bytesJeroenT
#27 optimize-2471232-27.patch16.49 KBJeroenT
#27 interdiff-2471232-25-27.txt564 bytesJeroenT
#25 interdiff.txt2.15 KBJeroenT
#25 optimize-2471232-25.patch16.49 KBJeroenT
#20 interdiff.txt1.25 KBJeroenT
#20 optimize-2471232-20.patch16.1 KBJeroenT
#18 optimize-2471232-18.patch15.3 KBJeroenT
#12 optimize-cache-merge-method-args-2471232-12.patch2.47 KBmariancalinro
#8 optimize-cache-merge-method-args-2471232-8.patch3.26 KBbogdan.racz
#5 optimize-cache-merge-method-args-2471232-5.patch2.46 KBbogdan.racz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bogdan.racz’s picture

Assigned: Unassigned » bogdan.racz
Wim Leers’s picture

Can you give some kind of progress indication, @rmboogie? :)

bogdan.racz’s picture

Still working on it. Yesterday I had some problems with the xhprof installation on mamp and osx.
I already made the modifications. Roughly the code for one of the function looks this:

  public static function mergeContexts($cache_context1 = array(), $cache_context2 = array(), $cache_context3 = array()) {
    // $cache_context_arrays = func_get_args();
    // $cache_contexts = [];
    // foreach ($cache_context_arrays as $contexts) {
    //   $cache_contexts = array_merge($cache_contexts, $contexts);
    // }
    // $cache_contexts = array_unique($cache_contexts);
    $cache_contexts = array_unique(array_merge($cache_context1, $cache_context2, $cache_context3));
    \Drupal::service('cache_contexts')->validateTokens($cache_contexts);
    sort($cache_contexts);
    return $cache_contexts;
  }

I left 3 arguments because of the following call:
Tests/Entity/EntityCacheTagsTestBase.php @400, @410
Is this the right way to approach it? I was going to profile it.

Wim Leers’s picture

Status: Active » Needs work

Alright, just wanted to make sure you're 1) not stuck, 2) still working on it :)


That looks like a step in the right direction, but you're accepting three parameters, not two. I'd call them $a and $b.

bogdan.racz’s picture

Assigned: bogdan.racz » Unassigned
FileSize
2.46 KB

I have added the patch, but haven't managed to make a profile test.
Please somebody, add some xhprof results.

mariancalinro’s picture

Assigned: Unassigned » mariancalinro

I will do some profiling for this.

joshi.rohit100’s picture

I think, we also need to update the commenting part.

bogdan.racz’s picture

I have updated the methods comments. Please review.

mariancalinro’s picture

Assigned: mariancalinro » Unassigned
Status: Needs work » Needs review

I did some tests. I run each function 10.000 times, and with or without the pach, and here are the results:

mergeContexts

Before patch

10000 runs, total run time 3.8855350017548, max run time 0.0035789012908936, min run time 0.00031113624572754.

After patch

10000 runs, total run time 3.4474279880524, max run time 0.0020530223846436, min run time 0.00027203559875488.

mergeTags

Before patch

10000 runs, total run time 3.330482006073, max run time 0.0016181468963623, min run time 0.00025105476379395.

After patch

10000 runs, total run time 2.8155419826508, max run time 0.0014889240264893, min run time 0.00021004676818848.

mergeMaxAges

Before patch

with Cache::PERMANENT as one of the parameters

10000 runs, total run time 2.1057970523834, max run time 0.001248836517334, min run time 0.00015687942504883.

without Cache::PERMANENT

10000 runs, total run time 1.4308922290802, max run time 0.0014550685882568, min run time 9.1075897216797E-5.

After patch

with Cache::PERMANENT as one of the parameters

Cache::PERMANENT is first_parameter:
10000 runs, total run time 0.69816279411316, max run time 0.001704216003418, min run time 3.0994415283203E-5.
Cache::PERMANENT is second_parameter:
10000 runs, total run time 0.78123903274536, max run time 0.0024521350860596, min run time 3.2901763916016E-5.

without Cache::PERMANENT

10000 runs, total run time 0.9782989025116, max run time 0.00097084045410156, min run time 5.1021575927734E-5.

The last submitted patch, 5: optimize-cache-merge-method-args-2471232-5.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 8: optimize-cache-merge-method-args-2471232-8.patch, failed testing.

mariancalinro’s picture

Status: Needs work » Needs review
FileSize
2.47 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 12: optimize-cache-merge-method-args-2471232-12.patch, failed testing.

Wim Leers’s picture

Nice! Those numbers look promising :)

If we can now get this green, then we're good to go :)

bogdan.racz’s picture

Assigned: Unassigned » bogdan.racz
mariancalinro’s picture

Assigned: bogdan.racz » Unassigned

The patch fails because there are some places that use more than 2 arguments for Cache::mergeTags method.
Here is one example in EntityCacheTagsTestBase.php @337

  // Generate the cache tags for the (non) referencing entities.
    $referencing_entity_cache_tags = Cache::mergeTags(
      $this->referencingEntity->getCacheTags(),
      \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
      // Includes the main entity's cache tags, since this entity references it.
      $this->entity->getCacheTags(),
      $this->getAdditionalCacheTagsForEntity($this->entity),
      $view_cache_tag,
      ['rendered']
    );

I suggest further analysis of the opportunity of this optimization for Cache::mergeTags.

Wim Leers’s picture

Yes, those calls simply need to be updated, to call Cache::merge*() multiple times. Almost all of those >2 cases are in tests anyway.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
15.3 KB

Called Cache::merge*() multiple times where it used more than 2 arguments.

Patch attached.

bogdan.racz’s picture

@JeroenT you can also update the comments as here, if it is ok.

JeroenT’s picture

FileSize
16.1 KB
1.25 KB

@rbmboogie,

I'm sorry, I took #12 as startpoint.

I created a new patch.

bogdan.racz’s picture

+++ b/core/lib/Drupal/Core/Cache/Cache.php
@@ -76,29 +70,25 @@ public static function mergeTags() {
+   *    Max age value to find..

One small typo coming from my patch, notice there are 2 points :)

Wim Leers’s picture

Status: Needs review » Needs work

The last submitted patch, 18: optimize-2471232-18.patch, failed testing.

The last submitted patch, 20: optimize-2471232-20.patch, failed testing.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
16.49 KB
2.15 KB

Fixed comment + some failing tests.

Status: Needs review » Needs work

The last submitted patch, 25: optimize-2471232-25.patch, failed testing.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
564 bytes
16.49 KB

Status: Needs review » Needs work

The last submitted patch, 27: optimize-2471232-27.patch, failed testing.

bogdan.racz’s picture

As far as I have checked, at least the following tests:

  • Drupal\block_content\Tests\BlockContentCacheTagsTest
  • Drupal\comment\Tests\CommentCacheTagsTest
  • Drupal\node\Tests\NodeCacheTagsTest

fail because of the following verification in EntityCacheTagsTestBase in line @426:
$this->verifyPageCache($nonempty_entity_listing_url, 'HIT', $nonempty_entity_listing_cache_tags);
Currently, I don't have more time to investigate the issue, as I will be leaving back home from the Drupal Dev Days.
If the issue is still unsolved by Monday, I can check it again.
Thanks for all the help.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
584 bytes
16.54 KB

@rbmboogie,

Thanks! I think i fixed the last failing tests now.

cilefen’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ruha’s picture

Assigned: Unassigned » ruha

At DrupalCon La, workingon reroll

ruha’s picture

Assigned: ruha » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll +LosAngeles2015
FileSize
16.47 KB
5.04 MB

Rerolled patch with 2 merge conflicts
Merge conflict in core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php line 55
Merge conflict in core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php line 100

Status: Needs review » Needs work

The last submitted patch, 33: optimize-2471232-33.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
16.47 KB

Tried applying the patch by JeroenT again with PhpStorm, got no conflicts. Patch attached.

Status: Needs review » Needs work

The last submitted patch, 35: optimize-2471232-35.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
2.14 KB
18.24 KB

This should resolve part of the failures.

Status: Needs review » Needs work

The last submitted patch, 37: optimize-2471232-37.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
1.08 KB
18.96 KB

This should fix all remaining failures.

sorressean’s picture

FileSize
14.48 KB
20.7 KB

Fixed a couple points with this patch:

1. Brought the patch up to date with latest commits.
2. Optimized the to avoie multiple frequent calls to Cache::mergeTags. the goal was to eliminate multiple calls that did not need to occur until after the array had been built for the last time.

Wim Leers’s picture

Wow, so many places that weren't yet using the right API! Thanks, great catches :)

borisson_’s picture

  1. +++ b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php
    @@ -124,12 +124,7 @@ protected function assertCacheTagsForFieldBasedView($do_assert_views_caches) {
    +    $tags_page_1 = Cache::mergeTags($base_tags, $entities[1]->getCacheTags(), $entities[2]->getCacheTags(), $entities[3]->getCacheTags(), $entities[4]->getCacheTags(), $entities[5]->getCacheTags());
    

    Cache::mergeTags should only have 2 arguments, so these should split up into multiple calls

  2. +++ b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php
    @@ -124,12 +124,7 @@ protected function assertCacheTagsForFieldBasedView($do_assert_views_caches) {
    +    $tags_page_1 = Cache::mergeTags($base_tags, $entities[1]->getCacheTags(), $entities[2]->getCacheTags(), $entities[3]->getCacheTags(), $entities[4]->getCacheTags(), $entities[5]->getCacheTags());
    

    Same as 1.

  3. @@ -272,15 +265,9 @@ protected function assertCacheTagsForEntityBasedView($do_assert_views_caches) {
    +    $new_entities_cache_tags = Cache::mergeTags($entities[1]->getCacheTags(), $entities[2]->getCacheTags(), $entities[3]->getCacheTags(), $entities[4]->getCacheTags(), $entities[5]->getCacheTags());
    

    Same as 1.

Status: Needs review » Needs work

The last submitted patch, 40: optimize-2471232-40.patch, failed testing.

sorressean’s picture

FileSize
0 bytes
1.81 KB

Updated to fix a couple stupid syntax errors which were preventing tests from running. Sorry about that.

I'm not sure what comments 42 and 43 are referring to, as that code has been fixed with my patch. Unless there are any issues, I will promote this to needs review after tests have hopefully passed.

sorressean’s picture

martin107’s picture

Status: Needs work » Needs review

Moving to needs review to trigger the testbot.

The last submitted patch, 44: optimize-2471232-44.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 45: optimize-2471232-44-final.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
14.4 KB
19.98 KB

I noticed a couple of weird things in the patch file that weren't in the interdiff so I went ahead and fixed those.

Status: Needs review » Needs work

The last submitted patch, 49: optimize-2471232-49.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 49: optimize-2471232-49.patch, failed testing.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Cache/Cache.php
    @@ -76,29 +70,25 @@ public static function mergeTags() {
    +    if ($a == Cache::PERMANENT){
    ...
    +    if ($b == Cache::PERMANENT){
    

    Might as well use ===

  2. +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php
    @@ -368,8 +368,10 @@ public function resetCache(array $entities = NULL) {
    +      $tags = Cache::mergeTags($tags);
    
    +++ b/core/modules/block/src/BlockViewBuilder.php
    @@ -48,6 +48,16 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
    +      $cache_tags = Cache::mergeTags($cache_tags);
    
    +++ b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
    @@ -91,12 +91,16 @@ public function testBlock() {
    +    $expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags);
    ...
    +    $expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags);
    
    +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -352,18 +352,36 @@ public function testReferencedEntity() {
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags);
    ...
    +    $non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags);
    

    I don't understand these final calls with one argument. They look like a mistake. Can we either remove them or document them?

  3. +++ b/core/modules/block/src/BlockViewBuilder.php
    @@ -48,6 +48,16 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
    +        $this->getCacheTags(), // Block view builder cache tag.
    +        $entity->getCacheTags() // Block entity cache tag.
    ...
    +        $plugin->getCacheTags() // Block plugin cache tags.
    

    We don't do inline comments like this, and the second element is missing a trailing comma

borisson_’s picture

Status: Needs work » Needs review
FileSize
7.75 KB
21.56 KB

Fixed test failure in TrackerTest.

Regarding comments from #53

  1. Agreed, fixed.
  2. I don't understand those either. Removed the calls. Testbot should agree that these weren't needed.
  3. Comma's are fine, we can only add 2 items so the trailing comma's would make incorrect. Removed the comments though. They didn't really add anything tbh.
tim.plunkett’s picture

Oh for #53.2, you're right about the commas, I misread it as part of an array, not in a function call, so you are correct.

daffie’s picture

Looks good to me. Just two remarks:

+++ b/core/lib/Drupal/Core/Cache/Cache.php
@@ -24,19 +24,16 @@ class Cache {
+  public static function mergeContexts($a = array(), $b = array()) {

@@ -53,19 +50,16 @@ public static function mergeContexts() {
+  public static function mergeTags($a = array(), $b = array()) {

Can we add type hinting to the parameters. In this way we make sure that the parameters are an array. Like: (array $a = array(), array $b = array())

+++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
@@ -372,24 +388,37 @@ public function testReferencedEntity() {
-
+    $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags);

Can you explain why you add this change. I do not think it is necessary.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
1.5 KB
21.48 KB

Made changes as suggested by daffie in #56.

JeroenT’s picture

FileSize
1.5 KB

This is the right interdiff...

The last submitted patch, 57: interdiff-2471232-54-57.patch, failed testing.

borisson_’s picture

Patch applies again now, changed the typehinting to use short array syntax (array $a = [], array $b = []). I had to make a change in the TrackerTest as well to also check for the 'user.node_grants:view' cache context.

Wim Leers’s picture

  1. +++ b/core/lib/Drupal/Core/Cache/Cache.php
    @@ -24,19 +24,16 @@ class Cache {
    +   *    Cache context array to merge.
    ...
    +   *    Cache context array to merge.
    

    s/context/contexts/

  2. +++ b/core/lib/Drupal/Core/Cache/Cache.php
    @@ -53,19 +50,16 @@ public static function mergeContexts() {
    +   *    Cache tag array to merge.
    ...
    +   *    Cache tag array to merge.
    

    s/tag/tags/

  3. +++ b/core/lib/Drupal/Core/Cache/Cache.php
    @@ -76,29 +70,25 @@ public static function mergeTags() {
    +   *    Max age value to find.
    ...
    +   *    Max age value to find.
    

    s/find/merge/

  4. +++ b/core/modules/block/src/BlockViewBuilder.php
    @@ -48,6 +48,15 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
    +      $cache_tags = Cache::mergeTags(
    +        $this->getCacheTags(),
    +        $entity->getCacheTags()
    +      );
    +      $cache_tags = Cache::mergeTags(
    +        $cache_tags,
    +        $plugin->getCacheTags()
    +      );
    

    Can we please put each of these on single lines? This is overly verbose.

  5. +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -363,17 +363,33 @@ public function testReferencedEntity() {
         $referencing_entity_cache_tags = Cache::mergeTags(
           $this->referencingEntity->getCacheTags(),
    -      \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags(),
    +      \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags()
    +    );
    +    $referencing_entity_cache_tags = Cache::mergeTags(
    +      $referencing_entity_cache_tags,
           // Includes the main entity's cache tags, since this entity references it.
    -      $this->entity->getCacheTags(),
    -      $this->getAdditionalCacheTagsForEntity($this->entity),
    -      $view_cache_tag,
    +      $this->entity->getCacheTags()
    +    );
    +    $referencing_entity_cache_tags = Cache::mergeTags(
    +      $referencing_entity_cache_tags,
    +      $this->getAdditionalCacheTagsForEntity($this->entity)
    +    );
    +    $referencing_entity_cache_tags = Cache::mergeTags(
    +      $referencing_entity_cache_tags,
    +      $view_cache_tag
    +    );
    +    $referencing_entity_cache_tags = Cache::mergeTags(
    +      $referencing_entity_cache_tags,
           $cache_context_tags,
           ['rendered']
         );
    

    This becomes an enormous statement. Let's put each merge statement on a single line, for legibility.

    Let's do that everywhere where we merge >2 things in tests. Otherwise those tests become quite confusing/painful to read.

Status: Needs review » Needs work

The last submitted patch, 60: optimize-2471232-60.patch, failed testing.

borisson_’s picture

Fixed test failures and remarks from Wim in #61. I'm not really happy with the changes in EntityCacheTagsTestBase for $page_cache_tags. It does make sense to fix the mergeTags call but the merged comment doesn't feel right.

     // Cache tags present on every rendered page.
-    $page_cache_tags = Cache::mergeTags(
-      ['rendered'],
-      // 'user.permissions' is a required cache context, and responses that vary
-      // by this cache context when requested by anonymous users automatically
-      // also get this cache tag, to ensure correct invalidation.
-      ['config:user.role.anonymous'],
-      // If the block module is used, the Block page display variant is used,
-      // which adds the block config entity type's list cache tags.
-      \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list']: []
-    );
+    // 'user.permissions' is a required cache context, and responses that vary
+    // by this cache context when requested by anonymous users automatically
+    // also get this cache tag, to ensure correct invalidation.
+    // If the block module is used, the Block page display variant is used,
+    // which adds the block config entity type's list cache tags.
+    $page_cache_tags = Cache::mergeTags(['rendered', 'config:user.role.anonymous'], \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list']: []);
+
Wim Leers’s picture

Status: Needs work » Needs review
  1. +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -339,16 +339,13 @@ public function testReferencedEntity() {
    -    $page_cache_tags = Cache::mergeTags(
    -      ['rendered'],
    -      // 'user.permissions' is a required cache context, and responses that vary
    -      // by this cache context when requested by anonymous users automatically
    -      // also get this cache tag, to ensure correct invalidation.
    -      ['config:user.role.anonymous'],
    -      // If the block module is used, the Block page display variant is used,
    -      // which adds the block config entity type's list cache tags.
    -      \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list']: []
    -    );
    +    // 'user.permissions' is a required cache context, and responses that vary
    +    // by this cache context when requested by anonymous users automatically
    +    // also get this cache tag, to ensure correct invalidation.
    +    // If the block module is used, the Block page display variant is used,
    +    // which adds the block config entity type's list cache tags.
    +    $page_cache_tags = Cache::mergeTags(['rendered', 'config:user.role.anonymous'], \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list']: []);
    

    I agree that this looks worse. Let's evaluate it case-by-case then. Let's revert this back to the previous state.

  2. +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -361,58 +358,25 @@ public function testReferencedEntity() {
    +    $referencing_entity_cache_tags = Cache::mergeTags($this->referencingEntity->getCacheTags(), \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags());
    +    // Includes the main entity's cache tags, since this entity references it.
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $this->entity->getCacheTags());
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $view_cache_tag);
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $cache_context_tags);
    +    $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, ['rendered']);
    

    This however, is much clearer!

borisson_’s picture

I couldn't go for a straight revert of the previous state, mergeTags was getting 3 arguments instead of 2. I think this solution is even more readable than the original solution.

The last submitted patch, 63: optimize-2471232-63.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 65: optimize-2471232-65.patch, failed testing.

Wim Leers’s picture

Yep, that's exactly what I meant :)

borisson_’s picture

Status: Needs work » Needs review
FileSize
25.91 KB
1.64 KB

Fixes the failures in FrontPageTest.

Status: Needs review » Needs work

The last submitted patch, 69: optimize-2471232-68.patch, failed testing.

Wim Leers’s picture

I already did a high-level IS update, but needs to be refined a bit more. Once that's done, and the nits below are fixed, this is RTBC.

  1. +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -361,40 +359,34 @@ public function testReferencedEntity() {
    +    $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags);
    

    s/$expectedTags/$expected_tags/

  2. +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
    @@ -422,9 +415,11 @@ public function testReferencedEntity() {
    +    $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags);
    

    Again.

  3. +++ b/core/modules/tracker/src/Tests/TrackerTest.php
    @@ -79,7 +79,9 @@ function testTrackerAll() {
    +    $expectedTags = Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags());
    

    Same.

borisson_’s picture

I updated the IS and added a beta evaluation. I think the beta evaluation is correct but I'm not sure.

Also fixed the nits from #72.

Wim Leers’s picture

Status: Needs work » Needs review
Wim Leers’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Made some further beta evaluation adjustments. Looking great! Thanks :)

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 9fab1ad on 8.0.x
    Issue #2471232 by borisson_, JeroenT, sorressean, rbmboogie, ruha,...

Status: Fixed » Closed (fixed)

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