Skip Navigation

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

Problem:
If you're experiencing performance issues after upgrading WPML and the ACFML plugin, where new field group translation code in ACFML is causing many thousand database calls and affecting WP REST API requests, leading to significantly increased response times.
Solution:
We recommend checking the errata page for Advanced Custom Fields Multilingual performance issues at https://wpml.org/errata/advanced-custom-fields-multilingual-performance-issues/.
As a temporary workaround, you can modify the code in

acfml/classes/Strings/STPluginHooks.php

by commenting out the problematic section and setting the plugin status to activated:

public function maybeRegisterFieldGroupsStrings() {<br />    //cbxx ACFML workaround for performance issues<br />    /*<br />    wpml_collect( acf_get_field_groups() )<br />        ->reject( [ $this, 'hasPackage' ] )<br />        ->map( [ $this->translator, 'registerGroupAndFieldsAndLayouts' ] );<br />    */<br /><br />    $this->setPluginStatus( self::PLUGIN_STATUS_ACTIVATED );<br />}

This change should reduce the server load to normal levels. However, please note that this solution might be outdated or not applicable to your case. If the issue persists, 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 you need further assistance, please open a new support ticket at our support forum.

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 9 replies, has 2 voices.

Last updated by Christopher Amirian 1 year, 10 months ago.

Assisted by: Christopher Amirian.

Author Posts
April 1, 2023 at 3:20 pm #13381381

lorenzP

After upgrading WPML and the ACFML plugin to their latest versions a few days ago we have massive performance issues on our production system which was reproducible on the staging environment as well. It took us a while to isolate the issue: the new field group translation code in ACFML performs many thousand database calls, also affecting WP REST API requests. Instead of a fraction of a second, request took at least 4-5 seconds and due to the queueing of PHP requests the overall response times were up to several minutes. This on a server with 8 CPU cores and 32 GB of memory.

Using the Query Monitor we saw that in every second request the following code gets executed which leads to 18000 icl_get_string_translations_by_id() calls:

    icl_get_string_translations_by_id()
    wp-content/plugins/wpml-string-translation/inc/functions.php:663
    WPML_Package->get_translated_strings()
    wp-content/plugins/wpml-string-translation/inc/package-translation/inc/wpml-package.class.php:326
    ACFML\S\Package->ACFML\S\{closure}()
    wp-content/plugins/acfml/classes/Strings/Package.php:153
    WPML\FP\Fns::WPML\FP\{closure}()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php:321
    ACFML\Strings\Package->getStatus()
    wp-content/plugins/acfml/classes/Strings/Package.php:174
    ACFML\Strings\STPluginHooks->hasPackage()
    wp-content/plugins/acfml/classes/Strings/STPluginHooks.php:58
    WPML\C\S\Collection->WPML\C\S\{closure}()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php:869
    array_filter()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php:869
    WPML\C\S\Arr::where()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Arr.php:504
    WPML\C\S\Collection->filter()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php:282
    WPML\C\S\Collection->reject()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php:870
    ACFML\Strings\STPluginHooks->maybeRegisterFieldGroupsStrings()
    wp-content/plugins/acfml/classes/Strings/STPluginHooks.php:66
    WPML\FP\Right->map()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php:207
    WPML\FP\Right->chain()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php:257
    WPML\FP\Promise->resolve()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Promise.php:24
    WPML\L\W\Hooks::WPML\L\W\{closure}()
    wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Hooks.php:50
    do_action('wp_loaded')
    wp-includes/plugin.php:517

As a first workaround we patched the code in acfml/classes/Strings/STPluginHooks.php:

	/**
	 * @return void
	 */
	public function maybeRegisterFieldGroupsStrings() {
		//cbxx ACFML workaround for performance issues
		/*
		wpml_collect( acf_get_field_groups() )
			->reject( [ $this, 'hasPackage' ] )
			->map( [ $this->translator, 'registerGroupAndFieldsAndLayouts' ] );
		*/

		$this->setPluginStatus( self::PLUGIN_STATUS_ACTIVATED );
	}

This change reduced the server load to normal levels again. We did not yet check the source code any further but this should be enough for you to fix this issue.

April 3, 2023 at 6:59 am #13387291

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you for the details. As I need to show the performance difference to the second-tier support to be able to report this,

I'd appreciate it if you can share with us the staging version of the website by making sure you set the next reply as private.

I will report this then to the second-tier and will keep in touch with you with the updates.

Thank you.

April 3, 2023 at 1:37 pm #13390769

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you for the login information. Unfortunately, the user does not have admin privileges to be able to check and see the difference when the code is there and when not.

Thanks.

April 3, 2023 at 1:44 pm #13390831

lorenzP

Sorry, now the user has the right role.

April 3, 2023 at 1:57 pm #13391041

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thankyou. I have access now. One last question, where do you see the impact? For example homepage? If you give me a page that you see the impact I can include in my report.

Thanks.

April 3, 2023 at 2:00 pm #13391051

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Also I want to ask if we are allowed to take a dump of your staging website for further investigation?

April 3, 2023 at 2:07 pm #13391113

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

I reported this, but I'd appreciate it if you answer the two replies below so I can add to the report.

April 3, 2023 at 2:47 pm #13391647

lorenzP

We see it on any page. The home page is a good test case.

Yes, you can create a temporary dump. Please remove all data once this issue is solved.

April 4, 2023 at 6:11 am #13396325

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

Thank you, there was no need for the duplication of the website. The development team came up with a temporary solution:

- Do not comment out the section that you have mentioned.
- Instead, replace the code below on thee same file from:

		if ( $this->needsRegistration() ) {
			Hooks::onAction( 'wp_loaded' )
				->then( [ $this, 'maybeRegisterFieldGroupsStrings' ] );
		} else {
			$this->setPluginStatus( self::PLUGIN_STATUS_DEACTIVATED );
		}

To:

		if ( ! defined( 'WPML_ST_VERSION' ) ) {
			$this->setPluginStatus( self::PLUGIN_STATUS_DEACTIVATED );
		}

		if ( $this->needsRegistration() ) {
			Hooks::onAction( 'wp_loaded' )
				->then( [ $this, 'maybeRegisterFieldGroupsStrings' ] );
		}

That will fix the performance issue.

A robust solution will be available in the next ACFML release which will be soon with a high priority.

Thank you.

April 4, 2023 at 8:20 am #13397477

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

We also published an errata here:

https://wpml.org/errata/advanced-custom-fields-multilingual-performance-issues/

Thanks.