soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
314 stars 29 forks source link

Make ACF + Oxygen faster by changing get_field() performance #747

Open wpsumo opened 4 years ago

wpsumo commented 4 years ago

Describe the feature you'd like to see included in Oxygen. ACF is great, but it comes with a performance bottleneck. Make ACF + Oxygen faster than anyone else by changing the way we fetch the field and values through get_field() to solutions that are more optimized for performance.

This way other builders on the market will not even be close to oxygen with dynamic data.

What are the use cases for this feature? Performance boost for dynamic content

Hurray for DRY Code! Yes, I think there is a better way than relying on get_field() or continually rewriting functions to retrieve ACF repeater and flexible content field values. The function get_all_custom_field_meta() is flexible, meaning your code stays DRY (Don’t Repeat Yourself), plus it returns all of the post meta values in a nice multidimensional array.

Oh, and it’s fast too. I ran some basic performance tests and get_all_custom_field_meta() was 50-100 times faster than get_field() in the example provided here (and 300+ times faster in other tests that I ran). The relative performance gap widens (gets better) as the config array increases in complexity because the function is doing far less work than get_field().

Give it a whirl!

This could be done manually with fixes and using a custom code block. But this ticket is to make it natively in oxygen or with a helper plugin making it faster. Bu still having the convenience of using the built-in dynamic data functions in oxygen.

https://www.timjensen.us/acf-get-field-alternative/ https://craigsimpson.scot/performance-considerations-working-with-acf

Fewer db queries using images in repeater: Images in repeater: https://aiocollective.com/blog/wordpress-advanced-custom-fields-optimization/

wpsumo commented 4 years ago

@wplit may be of your interest :D

vecchionico commented 4 years ago

The issues wit get_field() have now been resolved (the article you quoted is from 2017) and as of today there is no difference (performance wise) between ACF get_field() and the WP native function. See also https://www.billerickson.net/advanced-custom-fields-frontend-dependency/ and other articles from Bill Erickson for a wider discussion.

wpsumo commented 4 years ago

@vecchionico Yeah but couldn't find that this still wasn't an issue nor something connected to this in ACF's changelog. But thanks for sharing, so today is just the frontend dependency of disabling ACF it would still be loading the meta fields if using native get_post_meta().

Just great news, thanks!

I guess we could close this feature request ticket then. Just trying to find ways to better optimize dynamic content once using a lot of acf meta fields. Found out that php sync should be on the edge of performance over local json.

Using @wplit for easier local json with oxygen to a custom folder https://github.com/wplit/ACF-Local-JSON

Let me know if you have any tricks to improve wp admin and frontend once loading plenty of meta fields. Of course, using cache in the stack but cache is "Just one solution of a problem, and it should be used at the very end. Like the cherry on top of the cake."

wpsumo commented 4 years ago

Even though this is correct ACF and Oxygen is very slow in the builder and wp admin if using more than just a few custom fields.

Many php notices related to the acf integration which is reported over support tickets.

This is what I experience when loading edit a post:

Time with WPML + ACFML + ACF PRO + Oxygen: 21 seconds
Time with Oxygen only, without WPML and without ACFML: 21 seconds
Time WPML + ACFML + ACF PRO and  without Oxygen: 5 seconds