Did some profiling onto see where we are losing so much time compared to other (Drupal)UnitTests.
Turns out most time is actually spent in loading default config. Of the 20s it took to run Field: Unit Tests (with 7 test methods), 14s (70%) is spent in config_install_default_config(), 8s in views_config_import_create(), almost 10s is spent in Symfony\Component\Yaml\Parser::parse(), with 1250 calls to it. Note: Those times overlap of course :)
Then I remembered that profiling slows function calls down a lot (and w'ere talking about 13 million function calls here... o.0) so, I tested it without xhprof and the total test time went down to 7s.
Still, it's something that's worth checking, I think there are two separate ways to improve the speed of these tests.
- Load fewer default config files by splitting up views_test_config into multiple modules. That's probably the easiest way but it will only help with the tests and the downside is that the number of modules is going up, so it's more time spent in parsing .info files :) (which might become yaml files too ;))
- Speed up the actual yaml parsing. Installed the yaml extension, did some tests and came up with this:
$start = microtime(TRUE); $extension = yaml_parse_file('core/modules/views/tests/views_test_config/config/views.view.test_destroy.yml'); dpm($extension, 'extension'); dpm(round((microtime(TRUE) - $start) * 1000, 3), 'extension ms'); use Symfony\Component\Yaml\Parser; $parser = new Parser(); $start = microtime(TRUE); $symfony =$parser->parse(file_get_contents('core/modules/views/tests/views_test_config/config/views.view.test_destroy.yml')); dpm($symfony, 'symfony'); dpm(round((microtime(TRUE) - $start) * 1000, 3), 'symfony ms'); dpm($symfony == $extension, 'result is equal');
The dpm at the end confirms that the end result, at least in this case is the same, so it looks like it might actually be able to use it as a replacement if available. I did run that with and without xhprof, to also learn more about how much that is exactly slowed down.
extension ms => 2.911
symfony ms => 9.355
extension ms => 4.321
symfony ms => 29.101
The exact numbers vary a bit, but the trend is that extension ms without xprof = 1x, symfony ms without xhprof = 3x, and symfony ms with xhprof is 10x. So according to these numbers, we might be able to make the actual parsing ~3x times faster when using the yaml extension, if we can actually ensure that they result in the same structure.
PASSED: [[SimpleTest]]: [MySQL] 64,713 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 64,761 pass(es). View
PASSED: [[SimpleTest]]: [MySQL] 64,587 pass(es). View