[Extensive tests required] acf_get_field() performance bottleneck on local fields (~40%)#258
[Extensive tests required] acf_get_field() performance bottleneck on local fields (~40%)#258acf-extended wants to merge 1 commit intoAdvancedCustomFields:masterfrom acf-extended:master
Conversation
|
Thanks for your contribution. The 40% performance boost here is impressive, but also quite confusing. I suspect this boost might be a "false positive" gained by reducing functionality/compatibility. Let me explain. The "acf/load_field" filter is an extremely important one. It allows complex field types such as the Repeater and Flexible Content to load their sub field, amongst other functionality. It is only ever run once per field, when that field is first loaded, even if that field is "loaded" multiple times. It is important that this filter is run after the ACF field types have been registered, otherwise, the field type (Repeater / Flex) will not receive their chance to modify the I suspect that your PR is unintentionally preventing these classes from modifying the If my suspicions are correct, this PR could cause many PHP errors due to incomplete Logically, it does not seem correct for a "performance boost" to be achieved by running extra functionality on page load. This PR forces the "acf/load_field" filter to be run on every registered field, whether that field is actually loaded on the page. The current implementation would not doe this, which leads me to think this is a "false positive" type situation. Can you please perform some more testing with this PR?
Thanks mate. Interested in your results :) |
|
Hello, Thanks for taking the time to write some explanations. I'll run extensive tests on complex fields and test the cases you described. Meanwhile, I rename the PR, and will get back ASAP. Regards. |
Hello,
I was working on a faster alternative to
get_field()function when I discovered a performance bottleneck on local fields.Description:
The problem come from
acf_get_field()function, which is called every timeget_field()is invoked. What it does for each fields:acf_validate_field()$field['prefix'] = 'acf';acf/load_fieldfiltersstore('fields')for the next call.I was able to gain ~40% performance on
get_field()calls with local fields by doing so:If the field is local: Do not process
validate,prefix,acf/load_fieldinacf_get_field().This process is injected earlier, during the local fields registration, in
acf_add_local_fields().Finally, in
acf_get_field(), if the field is local, then simply return it.I ran a benchmark on local environment, on a page with 200
get_field()/ 200 different fields (local PHP field group):With the fix in this pull request:
I ran some tests on
acf/load_fieldfilter, and it works as expected.Let me know if you need more informations :)
Regards.
Edit: Also performed a benchmark on
get_fields()(which also callacf_get_field()):With the fix: