Problem/Motivation
Smart Date calls DateFormatter::format() with an empty string as $type and passes the pattern via $format. On Drupal core before 11.4, any $type other than 'custom' triggers DateFormatter::dateFormat(), which tries to load a
date_format config entity with the ID ''. In views rendering many Smart Date values this adds a noticeable number of unnecessary calls (see screenshots, before and after).
Core 11.4 skips the lookup for an empty type (#3520188: Do not try to load date format when custom date format is provided but not declared), but Smart Date still supports Drupal 10 and earlier 11.x releases, where the overhead remains. Passing 'custom' is also the documented way to use a custom pattern.
Steps to reproduce
- Drupal 10 or 11 before 11.4, create a view listing many entities with a Smart Date field using the Smart Date formatter.
- Profile the page (e.g. XHProf/Blackfire):
DateFormatter::dateFormat()is called for every formatted value.
Proposed resolution
Pass 'custom' as the format type in all calls that provide an explicit pattern:
SmartDateTraitSmartDatePluginTraitSmartDateTokensHooks
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | smart_date-missing-date-type.before.png | 208.5 KB | tobiasb |
| smart_date-missing-date-type.after_.png | 195.03 KB | tobiasb |
Issue fork smart_date-3519986
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 #2
tobiasbComment #3
tobiasbComment #5
tobiasbComment #6
tobiasbComment #7
tobiasbComment #8
tobiasb