There are a number of problems in ProductVariationFieldRenderer:

1) Field rendering is significantly slower than it needs to be.

Instead of renderField() calling renderFields() and taking the field it's interested in, we do the opposite: renderFields() calls renderField() on each field name separately. That means that for each field Drupal resolves the entity display (entity query + entity load), runs all hooks, does all post-processing. And what's most absurd, none of our code even uses renderField(), we only use renderFields(), so we can't say we prioritized single-field rendering performance.

2) getFieldDefinitions() is a public method that should probably be protected. It loads all field definitions just to determine which base fields to ignore (compared against the list in getAllowedBaseFields()). It would be much cheaper for ProductVariationFieldRenderer to simply have a list of base fields to skip.

3) renderFields() returns fields that do not have a formatter configured (cause they're hidden in the view display).
This has a cost, cause we output ajax commands for those empty fields as well, even though nothing can be done with them.

CommentFileSizeAuthor
#2 3010225-2.patch12.77 KBbojanz

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Status: Active » Needs review
StatusFileSize
new12.77 KB

Removed getFieldDefinitions() and the field whitelist. Made renderFields() render all fields at once. Expanded tests.

  • bojanz committed 1a2c56d on 8.x-2.x
    Issue #3010225 by bojanz: Optimize ProductVariationFieldRenderer...
bojanz’s picture

Status: Needs review » Fixed

  • bojanz committed 968a67f on 8.x-2.x
    Issue #3010225 followup: clean up ProductVariationFieldRenderer...

Status: Fixed » Closed (fixed)

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