Related to this https://www.drupal.org/project/eu_cookie_compliance/issues/3111617 (Call to a member function getEntityTypeId() on null) I found this big function eu_cookie_compliance_page_attachments() that has all the logic and resources how and when to show the popup. It seemed odd that although whatever the reason for the particular error might be, why was it executed if I haven't seen the popup for a very long time since I accepted it. Every single piece of code seems to be executed. I measured how long it takes on my local machine to load the function and while it was not much, still seemed pointless. In seconds:
0.019018888473511
0.018988847732544
0.015308856964111
0.016623020172119
0.016221046447754
0.016118049621582
0.017706155776978

Bigger issue I found was that at least on my local it seemed to break caching for anon users. When the function is canceled right in the beginning, it went from 400ms html load to 20ms.

Comments

hkirsman created an issue. See original summary.

hkirsman’s picture

I'm keeping this patch as minimal as possible, but probably needs more refactoring.

  • For example the default cookie name seems to come from js but now it's also coming from PHP - should remove code duplication and rely only on 1 source.
  • I actually would have canceled load only if $cookie_status == 2 because we have set it up only to be accepted. But I think current patch is more accurate?
hkirsman’s picture

Issue summary: View changes
svenryen’s picture

Can you give more information on how you measure the resource usage so I can reproduce?

hkirsman’s picture

In the beginning of eu_cookie_compliance_page_attachments() I added
$begin = microtime(true);
and to end of the same function:

  $end = microtime(true);
  drupal_set_message($end - $begin);

Anonymous full html caching I broke myself with the above code. I guess Drupal is smart enough to see the content changes.

I did some more tests with same logic on AWS t3.medium and t3.small. Calculated the seconds to ms

type: t3.medium, RAM: 4.0 GiB, CPU: 2 vCPUs
6
20
7
7
12
21

type: t3.small, RAM: 2.0 GiB, CPU: 2 vCPUs
23
23
12
25
23
14

Doesn't seem much but 25ms and 100 000 requests make 42 minutes

We would also get win from not adding the resources:
EU Cookie resources

hkirsman’s picture

Pascal-’s picture

Status: Active » Closed (duplicate)
Parent issue: » #3015612: [1.x][2.0.x] Better caching for cookie performance popup

Closing this issue since this is already suggested here:
https://www.drupal.org/project/eu_cookie_compliance/issues/3015612