Found Slow PHP Code
-
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.
- 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?
- 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.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Found Slow PHP Code’ is closed to new replies.