Problem/Motivation
The optimization mentioned below was mainly done to improve response times with the entitycache module installed - see #687712-29: Optimize rdf.module for displaying multiple comments:
does not bring any performance impact in core, but makes it possible for entitycache to cache these values.
However...
- The values for URLs are not guaranteed correct (I think - see #9 below)
- The way they are derived, combined with Drupal's automatic bubbling of cacheability metadata, can cause Drupal to throw exceptions a la #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it (even though Core itself doesn't).
Proposed resolution
revert #687712-32: Optimize rdf.module for displaying multiple comments
-- Original:
Problem/Motivation
In Drupal 7, #687712: Optimize rdf.module for displaying multiple comments had introduced an optimization in rdf.module for multiple comments:
Most of the extra time is spent in rdf_preprocess_comment() which calls url() multiple times (150 in total per page)
We should check if this is still necessary with all the new Drupal 8 APIs. For one, entity caching is available in core so we would be using this code directly, but at the same time, the entity output is cached, so we may not need this optimization in the end. Better to reduce the amount of code if possible.
Proposed resolution
revert #687712-32: Optimize rdf.module for displaying multiple comments if there is no gain from this old optimization.
Remaining tasks
evaluate if the code introduced in #687712-32: Optimize rdf.module for displaying multiple comments improves performance.
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#19 | Screenshot from 2021-12-20 14-12-43.png | 98.85 KB | vikashsoni |
#15 | 2335487-15.patch | 3.7 KB | Abhijith S |
#7 | 2335487-7.patch | 3.65 KB | roderik |
Comments
Comment #7
roderikI suspects the current situation also has cacheability issues which are solved by reverting #687712-32: Optimize rdf.module for displaying multiple comments.
First testing; commenting later.
Comment #8
roderikComment #9
roderikThe thing with the current code is, it's wrong although I'm not completely sure in what way it should be fixed if it stayed in place:
That second toString() can cause exceptions to be thrown if it's ever called from certain points in the code*. And it's entirely possible for code to indirectly call rdf_comment_storage_load() from such a point - even though Core doesn't do this. (See also: above code comment.)
However I'm doubtful that the solution is to change the ->toString() to ->toString(TRUE)->getGeneratedUrl(). (In other words, I don't trust the reasoning of the code comment above here: just because it can be called outside a render context, does not mean that cacheability metadata should just always be disregarded.)
The patch moves the code populating the RDF attributes back into rdf_preprocess_comment(), where we can just do toString() for both calls, which will never throw an exception (I assume, because a preprocess hook is always executed in a 'managed' render context?)
This ties in with the question: is the RDF metadata for 'entity_uri' and 'pid_uri' always supposed to be permanent and independent of whatever UrlGenerator logic / cache context? The unpatched code implies "yes" for the 'entity_uri' data. The patched code implies "no; take cache context into account". (I think. And I think that's right - though I'm not very experienced with this UrlGenerator / cache contexts stuff.)
So there are two open questions in my head:
--
* Exceptions are thrown because toString(default/FALSE) bubbles up cacheability metadata in the background. EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext() will detect bubbled-but-unhandled metadata and throw this exception.
And those points in the code are: 'within a regular controller route' but not within a method that explicitly handles bubbled-up metadata. See e.g. definition of "early rendering" in #2450993-118: Rendered Cache Metadata created during the main controller request gets lost or discussion / link to article in #2638686: Exception in EarlyRenderingControllerWrapperSubscriber is a DX nightmare, remove it.
And I'm sorry for being wordy but... it's just a lot of things to take in / think about, for a not-very-experienced core contributor. I still have to write things out, to be surer I don't make mistakes in reasoning.
Comment #10
roderikComment #14
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedPatch #7 can't be applied on 9.2.x.Needs reroll
Comment #15
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedRerolled patch #7 .Please check.
Comment #19
vikashsoni CreditAttribution: vikashsoni as a volunteer and at Zyxware Technologies commented#7 patch not applying in drupal-9.3.x-dev
Needs to Re-roll
for ref. sharing screenshot ....
Comment #21
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis could still be an issue.
RDF is moving out of core and into https://www.drupal.org/project/rdf moving there.