Problem/Motivation
When sorting facet results by display value, DisplayValueWidgetOrderProcessor::sortResults() reads each result's transliterated value up to 6 times every time it compares two results, each time going through the generic Result::get() storage bag.
Sorting compares results a lot, so on a page with many facet values this adds up to a huge number of repeated reads. The transliteration itself is already cached (the waste is just reading the same value over and over).
Also note that the Result::$transliterateDisplayValue property is present but unused: it was added in #3360426: PHP 8.2 compatibility, but that same change switched the processor to the storage bag instead, so the property was never populated.
Steps to reproduce
Proposed resolution
Read each value once per comparison into a local variable, and store it on a dedicated typed property with get/setTransliterateDisplayValue() accessors which is much faster than the storage bag (the same pattern already used for termWeight).
This reuses the existing $transliterateDisplayValue property.
Benchmark (sorting 2300 results, PHP 8.3): the sort drops from ~17.7 ms to ~5.3 ms (about 3× faster).
Remaining tasks
?
User interface changes
None
API changes
Adds get/setTransliterateDisplayValue() to ResultInterface and Result; the existing unused public $transliterateDisplayValue becomes protected.
Data model changes
None
Issue fork facets-3605900
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
Comment #3
herved commentedThis is already covered by DisplayValueWidgetOrderProcessorTest (testSorting, testUseActualDisplayValue) so I don't think new test are needed.