_field_info_collate_fields in this cachegrind I am staring at is called 7593 times. It is mostly called by field_info_field_by_id, 7004 times. That function is called by field_attach_load (1766 times) and _field_invoke_multiple (4607 times). Given that these functions are only called 140 and 182 times, it seems these are good points to stop walking up the ladder and inline field_info_field_by_id into them, saving 7593+7004-140-182 = 14275 function calls. That's a lot of function calls, my friends. To compare, previously we have static'd a variable_get into url() thinking it's a good saving which on this page saves 416 function calls.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Issue tags: +Performance

Tagging.

dhthwy’s picture

sounds like a good idea.

waiting for testbot.

Status: Needs review » Needs work

The last submitted patch, inline_field_info_field_by_id.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
FileSize
1.61 KB

"Oh bother!" said Pooh and renamed the variable.

catch’s picture

Patch looks great, will RTBC once test bot is green.

Status: Needs review » Needs work

The last submitted patch, inline_field_info_field_by_id.patch, failed testing.

yched’s picture

Status: Needs work » Needs review

+1 on the principle.
Though, to avoid calling a supposedly internal _field_info_collate_fields() function, may I suggest creating a new

function field_info_fields_by_id($field_id) {
  $info = _field_info_collate_fields();
  return $info['fields'];
}

function - we'd have field_info_field(), field_info_fields(), field_info_field_by_id(), field_info_fields_by_id(), would only make sense IMO.

chx’s picture

Great idea, I bet the $field_id argument was a copy-paste as you dont use it and you do not need it anyways.

dhthwy’s picture

Status: Needs review » Reviewed & tested by the community
yched’s picture

re @chx : right, quick copy / paste error :-).

+1 for RTBC - Although, while you're at it, don't you want to replace the occurrences of foreach() {field_info_field_by_id():} in field_sql_storage.module ? (if so, the change should be mirrored in field.api.php, since the code for the storage is taken out of field_sql_storage)

I guess there's a balance between the gain (reducing overhead of - snappy - function calls) and the cost (creating a temp copy of the array listing all fields)

chx’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.43 KB

There is no cost or it's minimal (80 bytes). PHP only copies on demand, otherwise it's just reference counting. Not sure what API change you are talking of, really.

But SQL storage, sure. We did not hit that of course 'cos we dont use no stinkin' SQL storage :)

yched’s picture

"Not sure what API change you are talking of, really"

I'm not talking about any API change - I mean that the code for hook_field_storage_load() in field.api.php is taken from field_sql_storage_field_storage_load().
Strictly speaking (and to encourage the use of the newly added field_info_fields_by_id() instead of repeated calls to field_info_field_by_id()), if field_sql_storage_field_storage_load() changes, the code example in hook_field_storage_load() should be updated too.

yched’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.44 KB

Patch is the same as #11, which I RTBC, plus updates the sample code in field.api.php

Thus, RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, inline_field_info_field_by_id.patch, failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
4.41 KB

Doh @ git diff --no-prefix

Dries’s picture

Does this result into a measurable performance improvement? Although this API addition make sense, it would still be good to know.

chx’s picture

Dries, I doubt. You need some very special pages (listing with a ton of fields and not much else) to make a measurable difference. I could create a freak install where I attach say 200 fields to every node then measure the front page (to stay within core) but such a creation would take more time than this worths. Saving 10K+ function calls is surely good and it has no stale effects because there are no new statics involved.

Dries’s picture

No need to create a 'freak install'. Thanks for your explanation though. I'll have another look at the patch. :)

webchick’s picture

LOL @ freak install. That's my new favourite phrase.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Performance

Automatically closed -- issue fixed for 2 weeks with no activity.