field_info_fields()
should be avoided. See https://drupal.org/node/1915646
The more memory-efficient field_info_field_map()
function was introduced in Drupal 7.22. I think modules can now reasonably depend on Drupal >=7.22, because there have been security releases since then.
The attached patch implements the recommended changes.
It results in a large memory saving (c. 10MB) on a real site I manage when loading a View for the first time. That is, because I have patched all the rest of the site's contrib modules in the same way. (I'm not sure why Name tokens are loading for each View but perhaps that's a different matter)
Comment | File | Size | Author |
---|---|---|---|
#8 | name-2204883-8-use-field_info_field_map-for-less-memory-overhead.patch | 1.33 KB | Alan D. |
| |||
#5 | name-memory-2204883-4.patch | 1.58 KB | pjcdawkins |
name-save-memory.patch | 861 bytes | pjcdawkins | |
Comments
Comment #1
Alan D. CreditAttribution: Alan D. commentedLike, but from the change log
i.e. the info file change will not be enforced (from pers. comms., I haven't tested this myself on early Drupal 7 versions)
Maybe
Comment #2
Alan D. CreditAttribution: Alan D. commentedAnd from the looks of it, are you sure it was this location that called the function?
@see name_views_data_alter()
The token one is actually cached, so would not be called that often, but it is still a valid performance improvement.
i.e.
Comment #3
pjcdawkins CreditAttribution: pjcdawkins commentedRe #2: it was revealed by a backtrace from field_info_fields() which was only getting called on loading a View from a cold views cache. Not that often but often enough in a site with lots of pages that contain different views. Re #1: fair point, I'll submit another patch when back in front of a computer
Comment #4
pjcdawkins CreditAttribution: pjcdawkins commentedNew patch attached.
BTW while the change log recommends
VERSION >= '7.22'
, as mentioned here, we should use version_compare() instead.Comment #5
pjcdawkins CreditAttribution: pjcdawkins commentedOops. Here's the patch.
Comment #6
Alan D. CreditAttribution: Alan D. commentednice, now I just need a couple of Drupal versions to test before committing...
Comment #7
webflo CreditAttribution: webflo commentedI think we should get this in but without the version_compare and just add a dependency to system module (>= 7.22).
Comment #8
Alan D. CreditAttribution: Alan D. commentedAs per webflo's old suggestion. Bumped to 7.40 for no real reason :P
Comment #10
Alan D. CreditAttribution: Alan D. commented3 years grace was enough time to update core, bumped again to 7.50 ;)