Some optimization for drupal_parse_info_format() for D7.
On large D7 projects, I found that it can take around 200ms on every cache clear, so it is worth working on performance.

Patch coming.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donquixote created an issue. See original summary.

donquixote’s picture

Profiling:
Regular D7 install with default profile plus devel and admin_menu.
/devel/php

$contents = array();
foreach (module_list() as $module) {
  $contents[$module] = file_get_contents(drupal_get_path('module', $module) . '/' . $module . '.info');
}

$t0 = microtime(TRUE);
for ($i = 0; $i < 1000; ++$i) {
  foreach ($contents as $module => $content) {
    drupal_parse_info_format($content);
  }
}
$dt = microtime(TRUE) - $t0;

dpm($dt);

Without patch:
2.7150158882141
2.762284040451
2.7313640117645

With patch:
1.228157043457
1.2305610179901
1.2188549041748

So, with patch is more than 2x as fast.
(This is only counting the function itself, not a full page request. You need to download a lot of contrib before the duration of this becomes relevant)

Profiling on other projects shows that huge info files like views.info also are processed faster.

Devel peak memory:
without patch: 14 MB
with patch: 14 MB
Not surprising, there is really no reason why this should affect memory.

-----------

Why is it faster?
- Value operations not applied to every array element, but only to those that .
- Key operations become faster if the same key (e.g. "files[] = ") is being repeated all over.

Regular expression tricks:
With PREG_PATTERN_ORDER, $matches[3] and $matches[4] contain " or ' as markers, so that the stripslashes() only needs to be applied to those lines that actually need it.
Also the constant stuff only needs to be applied to the lines that need it, thanks to preg_grep().

Maybe we could also borrow ideas from #1917530-7: drupal_parse_info_format crashes with PCRE 8.12