[Extensive tests required] acf_get_field() performance bottleneck on local fields (~40%) #258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_field
filtersstore('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_field
inacf_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_field
filter, 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: