Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing slow site performance when the Advanced Custom Fields Multilingual plugin is activated, it might be due to the high number of ACF field calls. In a case we investigated, activating WPML increased the load time significantly because it hooked into each ACF field call for translation, executing over 8000 times.
Solution:
To address this, we recommend two strategies:
1. Reduce the number of ACF field calls by modifying the theme to minimize usage of

acf_get_field

, especially for fields that don't require translation. Replace these with direct

get_post_meta

calls to bypass both WPML and ACF retrieval logic.
2. Use a filter introduced in ACFML 2.1.4 to bypass translation logic. Add the following code to your theme's

functions.php

or as a drop-in plugin:

add_filter( 'acfml_should_translate_acf_entity', function( $should, $field, $context ) {<br />    $should = false;<br />    static $customfield_settings;<br />    if ( ! is_array( $customfield_settings ) ) {<br />        $icl_sitepress_settings = get_option( 'icl_sitepress_settings' );<br />        $customfield_settings = $icl_sitepress_settings['translation-management']['custom_fields_translation'];<br />    }<br />    if ( $context === 'field' ) {<br />        $field_name = $field['name'];<br />        if ( isset( $customfield_settings[$field_name] ) && $customfield_settings[$field_name] === WPML_TRANSLATE_CUSTOM_FIELD ) {<br />            $should = true;<br />        }<br />    }<br />    return $should;<br />}, 10, 3 );

This code ensures that only fields marked for translation are processed, significantly improving performance.

If these solutions do not resolve your issue or seem outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by Bruno Kos 1 week, 6 days ago.

Assisted by: Bruno Kos.

Author Posts
October 9, 2024 at 8:17 pm #16272399

mikhaelA

Background of the issue:
I am trying to improve my site's load time. Currently, the load time without Advanced Custom Fields Multilingual is about 2 seconds, but with it, the load time increases to around 10 seconds. Here is a link to a page where the issue can be seen: hidden link.

Symptoms:
The website becomes slow when the Advanced Custom Fields Multilingual plugin is activated.

Questions:
Why does the Advanced Custom Fields Multilingual plugin slow down my site?
How can I reduce the load time when using the Advanced Custom Fields Multilingual plugin?

October 10, 2024 at 7:52 am #16273212

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Would you be willing to provide me with WordPress credentials so I could investigate the issue directly?

Can you also install https://wordpress.org/plugins/query-monitor/?

Let me know if I can test with and without ACFML, also, the performance issue is visible on hidden link, so this page will have visible issues on the performance side?

https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

I marked your next reply as private so that you can safely add credentials.

October 10, 2024 at 1:33 pm #16275467

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

I am checking this with our 2nd tier and will keep you posted.

October 11, 2024 at 7:51 am #16277854

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Can you please try the following:

1. Navigate to the file located at: `wp-content/plugins/acfml/classes/Strings/FieldHooks.php`.
2. Look for the method `\ACFML\Strings\FieldHooks::translateField` around line 56.
3. Modify the line:

   if ( self::isAcfFieldGroupScreen() ) {

to

   if ( self::isAcfFieldGroupScreen() || is_admin() ) {

Does it change anything?

October 15, 2024 at 5:32 pm #16292215

mikhaelA

Hi no, not really sadly, same TTFB:

hidden link

October 16, 2024 at 8:28 am #16294017

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

To troubleshoot this problem, I'll install the Duplicator plugin and generate packages for further debugging purposes. I'll ensure to exclude all media files to maintain a minimal package size. You can find more information about the process here: [link](https://wpml.org/faq/provide-supporters-copy-site/). Please confirm if this approach is acceptable to you.

October 17, 2024 at 12:42 pm #16300175

mikhaelA

Yes of course as I said this site is already a demo for us you can do what ever you want to fix this TTFB! Thx

October 17, 2024 at 2:18 pm #16300885

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

This has been escalated to our 2nd tier team team and may take some debugging time, I'll get back to you as soon as I have any news or questions for you.

October 23, 2024 at 10:44 am #16321357

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

We’ve been looking into the performance issues, and this case is somewhat unique in that the theme relies heavily on ACF fields. Without WPML activated, loading the home page triggers the ACF function `acf_get_field` over 8000 times. WPML then hooks into each of these calls to translate fields as needed, which means that translation logic is executed over 8000 times, leading to a significant performance hit.

There are two potential strategies to improve this:

1. **Reduce the Number of ACF Field Calls:**
The theme could be modified to minimize the number of `acf_get_field` calls, especially when retrieving field values that don’t require translation (e.g., fields without text labels, such as page options). These could be replaced with direct `get_post_meta` calls. This would bypass both the WPML translation logic and the ACF field retrieval logic, resulting in a much more efficient process.

2. **Use a Filter Introduced in ACFML 2.1.4:**
ACFML 2.1.4 introduced a filter that allows us to bypass translation logic altogether using this code:

 add_filter( 'acfml_should_translate_acf_entity', '__return_false' );

While this significantly improves performance, it may be too broad, as it skips translation for all custom fields. To make it more precise, we implemented a workaround that only applies translation logic to fields explicitly set to be translated. Here’s the code we used, which could be added as a drop-in plugin or directly into the theme’s `functions.php`:

   add_filter( 'acfml_should_translate_acf_entity', function( $should, $field, $context ) {
       $should = false;

       static $customfield_settings;
       if ( ! is_array( $customfield_settings ) ) {
           $icl_sitepress_settings = get_option( 'icl_sitepress_settings' );
           $customfield_settings = $icl_sitepress_settings['translation-management']['custom_fields_translation'];
       }

       if ( $context === 'field' ) {
           $field_name = $field['name'];
           if ( isset( $customfield_settings[$field_name] ) && $customfield_settings[$field_name] === WPML_TRANSLATE_CUSTOM_FIELD ) {
               $should = true;
           }
       }

       return $should;
   }, 10, 3 );

We tested this workaround and noticed a significant improvement in performance. Could you please have your team test it and let us know the results?

October 28, 2024 at 6:52 pm #16339511

mikhaelA

Hi!

Thanks for this! We'll test the code you sent over and share our feedback soon.

October 28, 2024 at 7:01 pm #16339519

mikhaelA

Hi!

We quickly tested this code on a blank test page, and it seems to have improved TTFB from 9-10 seconds to around 4 seconds. It's much better, but there's still room for improvement. Could you explain more about the logic behind this filter and how it impacts WPML/ACF performance so significantly? Thank you for your time.

October 30, 2024 at 9:20 am #16345577

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

The filter defaults to $should = false, effectively bypassing translation for all ACF fields unless explicitly marked for translation in WPML’s custom_fields_translation settings. By limiting the translation checks only to fields with the WPML_TRANSLATE_CUSTOM_FIELD flag, it cuts down the number of fields WPML processes.

The filter also caches the custom_fields_translation array locally with static $customfield_settings, preventing multiple calls to get_option for each ACF field. This reduces database queries and improves processing efficiency by accessing the settings only once per page load.

This optimized translation logic reduces WPML’s workload by skipping unnecessary checks and queries. By streamlining how ACF fields are handled, it directly impacts Time to First Byte (TTFB), leading to faster initial server responses and overall page load improvement.