_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.
Comment | File | Size | Author |
---|---|---|---|
#15 | inline_field_info_field_by_id.patch | 4.41 KB | yched |
#13 | inline_field_info_field_by_id.patch | 4.44 KB | yched |
#11 | inline_field_info_field_by_id.patch | 3.43 KB | chx |
#8 | inline_field_info_field_by_id.patch | 2.53 KB | chx |
#4 | inline_field_info_field_by_id.patch | 1.61 KB | chx |
Comments
Comment #1
chx CreditAttribution: chx commentedTagging.
Comment #2
dhthwy CreditAttribution: dhthwy commentedsounds like a good idea.
waiting for testbot.
Comment #4
chx CreditAttribution: chx commented"Oh bother!" said Pooh and renamed the variable.
Comment #5
catchPatch looks great, will RTBC once test bot is green.
Comment #7
yched CreditAttribution: yched commented+1 on the principle.
Though, to avoid calling a supposedly internal _field_info_collate_fields() function, may I suggest creating a new
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.
Comment #8
chx CreditAttribution: chx commentedGreat idea, I bet the $field_id argument was a copy-paste as you dont use it and you do not need it anyways.
Comment #9
dhthwy CreditAttribution: dhthwy commentedComment #10
yched CreditAttribution: yched commentedre @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)
Comment #11
chx CreditAttribution: chx commentedThere 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 :)
Comment #12
yched CreditAttribution: yched commented"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.
Comment #13
yched CreditAttribution: yched commentedPatch is the same as #11, which I RTBC, plus updates the sample code in field.api.php
Thus, RTBC.
Comment #15
yched CreditAttribution: yched commentedDoh @ git diff --no-prefix
Comment #16
Dries CreditAttribution: Dries commentedDoes this result into a measurable performance improvement? Although this API addition make sense, it would still be good to know.
Comment #17
chx CreditAttribution: chx commentedDries, 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.
Comment #18
Dries CreditAttribution: Dries commentedNo need to create a 'freak install'. Thanks for your explanation though. I'll have another look at the patch. :)
Comment #19
webchickLOL @ freak install. That's my new favourite phrase.
Comment #20
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.