Looking at http://rugbybreakdown.net/xhprof/xhprof_html/?run=4b4e34ee2a91c&symbol=t...
- element_children() is 24% of template_preprocess_field() - we can use a simpler alternative here.
- array_merge() is another 10% - a simple array addition will do.
I'm actually not sure a series of
$variables['foo'] = 'bar';
$variables['baz'] = 'goo';
would be faster than
$additions = array(
'foo' => 'bar',
'baz' => 'goo',
);
$variables = $addition + $variables;
Possibly microptimization since that same profling info only credits t_preprocess_field() with 1% of page load - although I'm not sure the test site is to date with recent template discovery optimizations, which mechanically raise the % cost of other funcs.
Comments
Comment #1
yched commentedWrong tag. Doh for typos in autocomplete suggestions.
Comment #2
effulgentsia commentedHere's a script that benchmarks the cost of theme('field') (or rather the cost of rendering a render array representing a field with #theme='field' vs. one without it).
On my system, the total render cost of a field render array is:
HEAD: 300us
Patch: 280us
20us saved per field = 1ms saved when there are 50 fields. Every little bit helps in trying to speed up field rendering.
Comment #3
effulgentsia commentedThis was a really helpful discovery and sparked an even faster solution in #652246: Optimize theme('field') and use it for comment body.
Comment #4
effulgentsia commented#652246: Optimize theme('field') and use it for comment body landed.