• Resolved chrismask

    (@chrismask)


    I am in the process of debugging my site php code with Code Profiler Pro, which debugs all plugins, files and each of their functions for speed. As expected, translatepress is the slowest plugin on my site. Adds 0.3s in each page generation, in my site with my current trp database. I am fixing slow code and will show my results here so we can discuss.

    1. My slowest function was TRP_Process_Gettext->process_gettext_strings adding 0.1s to each page generation time. I looked it up and did some tests and found out that its requested several times inside the file with different parameters. There was a pattern of differentiating the parameters by woocommerce domain. 3 pairs of functions that call it with each pair having the if(domain===woocommerce) in it. The last pair didnt have this if(domain===wocommerce) in it, while the function name indicated that its used for woocommerce domain. So I just added this if statement as in the other ones. public function woocommerce_process_gettext_strings_no_context( $translation, $text, $domain ){if ( $domain === ‘woocommerce’ ) {$translation = $this->process_gettext_strings( $translation, $text, $domain ); return $translation; As it seems, only setting the woocommerce domain for this function with no context translations, made the whole file 10 times faster and reduced whole translatepress plugin bottleneck from 0.3s to 0.2s. https://imgur.com/a/a0y5xgF On my frontend tests, didnt see any problem, and the function name indicates that this if statement was missing in any case. Can you confirm?
    2. I will update this post on each of my findings to help you speed up the plugin. It seems that if I disable gettext from advanced settings, another 0.05-0.1s can be saved, so will look into these gettext functions more.
    • This topic was modified 1 year, 9 months ago by chrismask.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Thank you for reaching us!

    I had a discussion with our developers regarding what you said and we created a task for this issue that you reported.

    You can update us regarding this so we will track this.

    If there`s anything else, please let me know!

    Kind Regards,

    Thread Starter chrismask

    (@chrismask)

    Update:

    2nd thing I did was deactivating all insert database capabilities by inserting return on the beginning of every function id insert-update class file and some files on class-query that insert strings in database. The same can happen easily, one simple option of Disable new strings database insertion or something. After, I have removed all useless strings from gettext and dictionary table. On English (default) I removed all untranslated strings, and on my second language all strings that I didnt need. On create_gettext_translated_global function which sets all gettext strings as global (completely unneeded), in foreach I skipped all untranslated strings,. On process_gettext_strings I skipped all new strings insertion calling and some other small modifications.

    These two functions, process_gettext_strings and create_gettext_translated_global account for almost all speed of the plugin and these two simple modifications speed up the plugin 10 times for english (with very small gettext table) and 5 times for greek (with 4000 rows of translations). Now translatepress plugin php runtime from 0.4s went to 0.05-0.1s, which is a great improvement without big compromise, and can easily be achieved with some small improvements. I am sure the plugin creator can do this with 1 hour work, and can even improve it further with some further modifications.

    As of now, I havent seen any visual problems, translations work well. Some of my observations are: 1. You firstly need to stop all gettext table insertions before stopping all gettext strings from being loaded into global variable in create_gettext_translated_global, since other functions detect uninserted strings and insert them again.

    Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Thank you for your patience!

    Our developers fixed this in the last update.

    You can update TranslatePress to the latest version and see how it goes.

    Let me know about this!

    Kind Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Found Slow PHP Code’ is closed to new replies.