field_modules_enabled($modules) was added to field.module in 7.14, and really does a number on the speed of an install profile - the result is something like a 2x to 5x slowdown during the module installation batch calls depending on whether or not you are heavily using features modules (e.g. lots of content types and fields being defined).

/**
 * Implements hook_modules_enabled().
 */
function field_modules_enabled($modules) {
  // Refresh the 'active' status of fields.
  field_sync_field_status();
}

This is a big deal for groups like us, who have large install profiles.

From running profiling on the install, this slowdown appears to be just a very large number of operations (repeated module_invoke calls all the way down...) resulting from the field_sync_field_status() call - no one cause leaps out.

If you do this:

/**
 * Implements hook_modules_enabled().
 */
function field_modules_enabled($modules) {
  // Refresh the 'active' status of fields, but only after an install is
  // completed.
  if (variable_get('install_task') == 'done') {
    field_sync_field_status();
  }
}

You end up with speed restored to the 7.12 level, but you you don't get a proper installation - fields are not correctly attached to entities. So further investigation needed here to figure out why this is so much slower than the way it used to work.

Comments

bojanz’s picture

As I said in #1574716: Avoid unnecessary cache rebuilds when creating and updating fields:

And we really need to do something about field_sync_field_status(), it runs every time the cache is cleared or a module enabled, and rebuilds the module list from scratch. On a slow VM, this means that field_modules_enabled() takes 2min out of 7min of total install time (with lost of post-install tasks).
We have an internal patch testing whether it's fine to replace system_rebuild_module_data() with module_list() in field_sync_field_status(), should make it into the core issue queue soon.

That's something we should approach.

exratione’s picture

StatusFileSize
new721 bytes

After some digging, it looks like the issue is spawned by a call to l() of all things, in field_system_info_alter(). That can safely be discarded during install.

A patch is attached.

exratione’s picture

Profiling with the patch #2 in place, the cost of field_sync_field_status() drops from 4.5s to 0.8s for a batch install call late in our install profile.

I agree that it would be nice to do away with system_rebuild_module_data() call in field_sync_field_status() - that's pretty much all of that 0.8s cost right there.

mrfelton’s picture

Version: 7.14 » 7.x-dev
Status: Active » Needs review
StatusFileSize
new740 bytes

Patch updated - last one appeared to be corrupt.

swentel’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
StatusFileSize
new921 bytes

Let's fix this in D8 first. Other approach by checking on MAINTENANCE_MODE which makes more sense than relying on a variable. This way, this hook is not fired either on update.php - or any other maintenance mode where this absolutely does not make any sense.

swentel’s picture

Status: Needs work » Needs review

Euh, wrong status

swentel’s picture

StatusFileSize
new908 bytes

Ah man, totally wrong

swentel’s picture

Version: 8.x-dev » 7.x-dev

This is now used in D8 - also field_modules_installed will be removed once the concept of active and inactive fields is gone in #1503314: Remove the concept of active / inactive (field types, storage) from Field API

swentel’s picture

Issue summary: View changes

Correcting understanding.

jibran’s picture

Issue summary: View changes
Status: Needs review » Patch (to be ported)

according to #9.

dcam’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new889 bytes

Backported #8 to D7.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.