I noticed that popup rendering is quite costly because it involves a lot of different templates, messages, and other elements that need to be prepared and rendered before they can be displayed.

However, once we decide whether or not the popup should be shown, I believe the processing involved is the same for everyone.

Unfortunately, we can’t use render cache, but maybe we can store everything in a single regular cache entry and fetch it instead of having to build it over and over again on every page?

Comments

Berdir created an issue. See original summary.

svenryen’s picture

Category: Bug report » Feature request

Great idea. I'd love to see some better caching.

Just to understand the implications of the slowdown. Did you check whether the caching situation improves when the Internal Dynamic Page Cache or Internal Page Cache are enabled?

In D7, we're storing a cache item with all the settings, including the rendered templates. Do you think that's a good approach, or does D8 have something better to offer?

berdir’s picture

> Just to understand the implications of the slowdown. Did you check whether the caching situation improves when the Internal Dynamic Page Cache or Internal Page Cache are enabled?

Once cached it should be fine. But since it is a top-level element and not a block or so, it needs to be recalculated for every page * cache context variations (e.g. each set of user permissions).

I would need to check if the render cache/lazy builder could be used, it would need to refactored a bit I guess. If we would manage that, it could even be a possibility to auto-placeholder the whole thing.

svenryen’s picture

Take a look at the D7 codebase. Around line 135 we have some caching that seems to do the job. Maybe something similar can be achieved in D8? I didn't do the initial port, so I don't know why the caching was removed.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new18.41 KB

Had another look, I think reusing render caching would be quite tricky, so I just did some custom caching, did not test this at all, so it's most likely broken ;)

Status: Needs review » Needs work

The last submitted patch, 5: eu_cookie_compliance-caching-3015612-5.patch, failed testing. View results

svenryen’s picture

Thanks for the patch. Sorry that we don't have tests :)

The cid needs to also factor in the theme and the the active domain if the domain module is enabled.

svenryen’s picture

Issue tags: +Needs reroll

The patch also needs a re-roll against latest -dev.

mirakolous’s picture

I have re-rolled this patch to work with the latest dev. I have also added the active domain and theme in the cache tag string. I did not test the domain portion of this so we would definitely want to test that or remove that before patching dev.

mirakolous’s picture

Status: Needs work » Needs review
svenryen’s picture

Thanks. I'll have a look.

Pascal-’s picture

svenryen’s picture

The proposed patch didn't apply cleanly. Here's an updated patch.

svenryen’s picture

When the domain module is available, we also need to check if there are domains configured, or else the call to
\Drupal::service('domain.negotiator')->getActiveId() fails. This can be resolved by checking count(Domain::loadMultiple()).

Here's an updated patch that resolves that issue and also re-rolls the rest of the changes against the latest -dev.

Would be nice if somebody can review the patch.

neslee canil pinto’s picture

Status: Needs review » Needs work

@svenryen patch is not getting applied. Needs a re-roll against the latest dev.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 29843  100 29843    0     0  36349      0 --:--:-- --:--:-- --:--:-- 36349
error: patch failed: eu_cookie_compliance.module:134
error: eu_cookie_compliance.module: patch does not apply
suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new29.65 KB

Re-rolled patch please review!

Status: Needs review » Needs work

The last submitted patch, 16: 3015612-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

svenryen’s picture

Title: Better caching for cookie performance popup » [1.x] Better caching for cookie performance popup
svenryen’s picture

Title: [1.x] Better caching for cookie performance popup » [1.x][2.0.x] Better caching for cookie performance popup
maximpodorov’s picture

The patch for 8.x-1.9 release is the copy of #13 patch adapted to renamed configuration variables (#2969161: Form technical names mixed up for labels?).

svenryen’s picture

@maximpodorov, the patch in #20 won't apply. Would you be able to make a patch against the latest -dev?

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new27.4 KB

Re-rolled patch, please review

Status: Needs review » Needs work

The last submitted patch, 22: 3015612-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

svenryen’s picture

Status: Needs work » Needs review
svenryen’s picture

Status: Needs review » Needs work

We can't use the patch from #22. It misses the fix from #14, where \Drupal::service('domain.negotiator')->getActiveId() was added to fix a fatal crash. I see the code was dropped in #20

Can you please make sure you don't leave out any code from the previous patches when you re-roll?

Also, there are code styles to fix. See the diff in #23.

svenryen’s picture

The patch also doesn't pick up on the many changes that's been made to the code base since #13, I'm fixing that now.

svenryen’s picture

Here's a patch that resolves all the issues with #22

svenryen’s picture

StatusFileSize
new16.96 KB

Here's an interdiff for information.

neslee canil pinto’s picture

Status: Needs review » Reviewed & tested by the community

#27 looks good to me. Moving to RTBC.

  • svenryen committed 7551cdf on 8.x-1.x
    Issue #3015612 by svenryen, Suresh Prabhu Parkala, Berdir, Mirakolous,...
svenryen’s picture

Status: Reviewed & tested by the community » Fixed
svenryen’s picture

Status: Fixed » Closed (fixed)

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

pianomansam’s picture

We can't use render cache, but we might be able to just put everything into a single regular cache entry and fetch from that instead of having to build it over and over again on every page?

Why can't we use render cache? The three existing parts of the $cid (language ID, domain ID, theme name) are already covered by the render cache. In fact, having to add info from another module, the domain module, is a code smell that perhaps this isn't the best approach. The domain module's documentation suggests users add the url.site cache context so that the cache can vary based on the domain. So the EU Cookie Compliance module shouldn't need to worry about the domain. However, because it micromanages this part of the renderable content, it needs to account for all the ways it may vary.

In working on the #3480626: DNT (Do Not Track) header detection not working when caching enabled bug, I traced the issue to the custom cache entry's $cid not varying based on the DNT header. If a custom cache entry was not deployed, that bug would easily be fixed with one line of code adding the DNT header to the cache context. Instead, we need yet another variance of the $cid.

So to summarize, why can't we let the render cache do its job? Micromanaging a separate cache entry causes additional complexity, makes it easier to cause bugs (DNT header issue), and causes this module to care about unrelated modules (domain module).

svenryen’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

Reopening this issue after comment from @pianomansam.

atowl’s picture

Status: Active » Postponed (maintainer needs more info)

hi @pianomansam

How much of this change are we talking about undo'ing?

pianomansam’s picture

@atowl the merge request on #3480626: DNT (Do Not Track) header detection not working when caching enabled does what I propose (removing the custom cache entry). The only line of code that adds the DNT header is the cache context addition.

+  $variables['#cache']['contexts'][] = 'headers:DNT';
atowl’s picture

Hi @pianomansam,

So given that line is in the request of #3480626, we could close this issue and merge that instead?

pianomansam’s picture

@atwol yes, you absolutely could. However, I wanted to point out that #3480626 undoes much of the work done in this issue.

atowl’s picture

Status: Postponed (maintainer needs more info) » Fixed

OK thanks for the information @pianomansam,

I'll (re) close this as fixed, and i'll look at merging #3480626, and any further disucussion in that thread.

Status: Fixed » Closed (fixed)

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