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
addressfield_get_administrative_areas(
) calls t()
nearly 1000 times in one call.
On the shipping page I noticed it this function was called only 8 times, but it was amounting to 80ms wall time.
Proposed resolution
Statically save the first set.
Remaining tasks
RTBC & Commit
Comment | File | Size | Author |
---|---|---|---|
#5 | 2507665-5.patch | 1.79 KB | joelpittet |
#2 | 2507665-1.patch | 2.45 KB | joelpittet |
#2 | t-before.png | 146.87 KB | joelpittet |
#2 | t-after.png | 131.92 KB | joelpittet |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedI'd also argue that most administrative areas shouldn't be passed through t() in the first place.
Comment #2
joelpittet@bojanz That may take more thought into which should or shouldn't use t(). Feel free to take this issue and run with it.
I was also thinking, why is it getting them all, why not only return ones for the country requested?
Before
After
Comment #3
SurajHo CreditAttribution: SurajHo commentedNice job on the patch. I went from almost 180000 calls to a little under 47000. It would be nice if this patch would be added to the next release although I'm also wondering why doesn't just return the countries that are needed.
Comment #4
bojanz CreditAttribution: bojanz commentedI've now significantly reduced our usage of t(): http://cgit.drupalcode.org/addressfield/commit/?id=2ffb831
(following #1 and a discussion on IRC with joelpittet).
A static and/or a refactoring of how the data is stored is the next step.
Marking as "needs work" because the patch won't apply anymore, but feel free to leave it to me.
Comment #5
joelpittetI'm going to leave the additional t() for JM out of this patch because I'm sure if they are needed we can open a new issue.
Comment #6
joelpittetComment #7
bojanz CreditAttribution: bojanz commentedMoved the static as discussed, and documented it. Thanks!