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.
Problem/Motivation
#2552873: node/1 flamegraphs uncovered that EditorManager::getAttachments()
is ridiculously expensive.
This is because the comment form loads all editors at once, in order to show only one editor.
Proposed resolution
Either cache the result, or only load one editor in editor_load().
Remaining tasks
Profile node/1 with comments enabled, confirm this is still an issue and compare the two proposed approaches.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#25 | cache-2553695-25.patch | 6.09 KB | mr.baileys |
#25 | interdiff.txt | 3.5 KB | mr.baileys |
#22 | cache-2553695-22.patch | 6.12 KB | mr.baileys |
#22 | interdiff.txt | 1.36 KB | mr.baileys |
#20 | cache-2553695-20.patch | 6.32 KB | mr.baileys |
Comments
Comment #2
Wim LeersComment #4
Wim LeersComment #5
dawehnerI'm sorry but this piece of code is confusing ... does that do anything? In case it does, it feels magic for me, at least add a comment.
Comment #6
Wim Leers#5: Yeah, it sucks. But it's the same as the other code in that file, where it is copied from. Not every text format has a text editor associated with it. That if-statement is there in case the text format does not have a text editor.
Comment #7
Wim LeersWe need this in case a text format that didn't have a text editor before now has one.
Hence all of this can be removed, because it's already implied by the list cache tag.
This then also happens to fix #5 :)
Comment #8
dawehnerWhat about fixing the actual code, and make the actual loading code not public and improve the code to even in case of a cache miss, not load invidiual entities over time ...
Comment #9
Wim LeersHonest oversight in a quick PoC patch ;)
Please look at
editor_load()
, you'll see that this is untrue.Comment #10
dawehnerAs wim explained these numbers are a little bit unfair. This seems to be the first thing which loads the entity type definitions.
If this does not load it, something else might?
Let's have a profiling to see how much actually is saved.
OH, the fuck. I think then not using it is perfect. How likely is that we need all editors on every request?
Comment #12
Wim LeersI agree with your assessment.
This goes back to how
wysiwyg
module works, and IIRC sun and/or quicksketch felt very strongly back then that we should keep this pattern.(Perhaps now they would agree that it no longer makes sense, now that D8's entity system works quite differently. I don't remember the exact reasons.)
Comment #13
moshe weitzman CreditAttribution: moshe weitzman at Acquia commentedComment #14
Wim LeersThis is a performance improvement that we can do in 8.1.x.
Comment #16
lokapujyaComment #18
lokapujyaSeems this is waiting on profiling,but just looking into the fails. Why is the editor settings array different? Do the tests just need to update due to the changes in the patch? Here is an attempt.
Comment #20
mr.baileysThe tests are failing since they are testing
hook_editor_js_settings_alter()
, and the result of this hook is now cached in getAttachments(), providing the test with stale cached settings-data.Either we move the result of altering the settings through
hook_editor_js_settings_alter()
outside of caching, or we include it in the cache (as I think is the default way of caching in core) and we have the test explicitly invalidate the cached attachments.Besides the test failures, when calling
EditorManager->clearCachedDefinitions()
, only the definitions are cleared, while the attachments-cache remains. This seems like a bug, patch attached that ensures that the attachments-cache is cleared whenever the definitions cache is cleared by setting the editor_list cache tag on the definitions cache backend.Comment #21
Wim LeersYay, thanks for pushing this forward! This is very very close now.
This totally makes sense!
Not necessary.
This comment is true, but the specific reason for this being problematic is the line above: it uses
\Drupal::state()
to cause a change in output!Any time a test uses state to cause different output (which is fine btw), you need to explicitly clear cache.
I think the comment should say that.
Comment #22
mr.baileysThanks Wim! Removed the unused use statement and altered the wording on the comment.
Comment #23
Wim LeersPerfect! Now all that remains is some profiling as per #10.
Comment #24
dawehnerJust some driveby review.
Let's use the entity type manager.
Comment #25
mr.baileysThanks dawehner, replaced EntityManager with EntityTypeManager.
Comment #26
jibranI presume we need tests for this bit of additional code.
Comment #40
smustgrave CreditAttribution: smustgrave at Mobomo commentedif still a valid task can we get an updated issue summary please. What exactly is being proposed to fix?
Comment #41
catchUpdated the issue summary, I doubt anything much has changed here looking at editor_load() in 9.5.x, so probably original findings are valid but we'll need to validate.