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

yched’s picture

Issue tags: -Perfomance +Performance

Wrong tag. Doh for typos in autocomplete suggestions.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.3 KB

Here'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.

effulgentsia’s picture

Status: Reviewed & tested by the community » Postponed

This was a really helpful discovery and sparked an even faster solution in #652246: Optimize theme('field') and use it for comment body.

effulgentsia’s picture

Status: Postponed » Closed (fixed)