Problem/Motivation

A few weeks ago, Tom Keitel (hctom) sent this message on Slack:

I realized, that a layout builder override heavily using ui_patterns and sdc for displaying all its content elements (5 different blocks with mapped SDCs via ui_patterns) ran into severe performance issues (with dynamic-page and render cache disabled).

digging through the code and doing some profiling, I saw that SourcePluginManager::isApplicable() is loading all context definitions - which is not the actual problem here - and Drupal serializes all of them in the end of the call graph during __sleep() of those classes.

so I added a simple return TRUE for the isApplicable() function to see the difference without all the serialization etc. and it turned out, that the execution gets approx. 10-20x faster

here are the overall results for accessing the page with all context checks still enabled:

  • Total Incl. Wall Time (microsec): 19,323,806 microsecs
  • Total Incl. MemUse (bytes): 36,098,848 bytes
  • Total Incl. PeakMemUse (bytes): 42,147,720 bytes
  • Number of Function Calls: 38,529,077

And these are the results for accessing the page with isApplicable() just returning TRUE:

  • Total Incl. Wall Time (microsec): 1,085,344 microsecs
  • Total Incl. MemUse (bytes): 41,974,512 bytes
  • Total Incl. PeakMemUse (bytes): 45,152,840 bytes
  • Number of Function Calls: 2,014,698

and at last, here is the part of the call graph for isApplicable() when doing all context checks:

in this graph, you can also see that the hashing in SourcePluginManager::getDefinitionsForContextsRefined() consumes a lot of resources as well.

He got the same results with layout builder overrides, and asked:

as i do not know the code really good enough (yet), I was a wondering, if there is a better solution to only check the contexts necessary for each plugin and not load all of them each time?

Proposed resolution

What can we do to improve the performance of SourcePluginManager::isApplicable() and SourcePluginManager::getDefinitionsForContextsRefined() ?

CommentFileSizeAuthor
image_720.png155.82 KBpdureau
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pdureau created an issue. See original summary.

pdureau’s picture

Category: Task » Bug report

just_like_good_vibes made their first commit to this issue’s fork.

just_like_good_vibes’s picture

Assigned: Unassigned » christian.wiedemann
Status: Active » Needs review

I did a patch, exactly where i thought it was necessary (two specific places).
Perfs were greatly improved !
i tried in other places, but has no significant impact and seems counter-productive.

please review

just_like_good_vibes’s picture

pdureau credited htom.

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs review » Fixed
pdureau’s picture

Status: Fixed » Closed (fixed)