[Vtigercrm-developers] performance and profiling

Prasad prasad at vtiger.com
Thu Jul 17 16:33:01 GMT 2014


Good catch - we will scan through and optimize.

*Connect with us on: *Twitter <http://twitter.com/vtigercrm> *I* Facebook
<http://www.facebook.com/pages/vtiger/226866697333578?sk=wall> *I* Blog
<https://blogs.vtiger.com/>* I* Wiki
<http://wiki.vtiger.com/index.php/Main_Page> *I *Forums
<https://discussions.vtiger.com>*I* Website <https://www.vtiger.com/>


On Thu, Jul 17, 2014 at 7:44 PM, Alan Bell <alan.bell at libertus.co.uk> wrote:

> I have been doing some profiling of vtiger using xdebug and webgrind, to
> make it a bit quicker to load pages and navigate about
>
> the to_html function in include/utils/utils.php
> http://trac.vtiger.com/svn/vtiger/vtigercrm/branches/6.1.
> 0/include/utils/utils.php gets called a *lot* like 1700 times to load a
> page and accounts for 20% of the page load time.
>
> This function does a bunch of decisions around what is in $_REQUEST to see
> whether or not it should replace < with < and so on for display. All
> those if statements get evaluated for every call, but as it is always based
> on the same information it always comes to the same result, which is either
> return the unmodified string or return htmlentities($string,ENT_QUOTES,$default_charset)
> or do a preg_replace if you are not using utf-8.
> This would be a lot faster if the decisions were done once, in index.php
> or somewhere early in the process, then set a global on whether it should
> or should not convert html so the to_html function itself is much smaller
> and faster.
>
> I have an example patch below that I think works OK, it possibly breaks
> support for not using utf-8, but seriously, who doesn't use utf-8 these
> days? It basically decides *once* whether this is a convert to HTML type
> request or not, and if it is going to be converting it flings everything
> through htmlentities, without checking to see if it is a string first and
> without doing much at all, no converting charset names to upper case, no
> preg_match etc.
>
> This reduces the to_html function from 20% of the load time to just under
> 10% of the load time for a detail view.
>
> Alan.
>
> Index: include/utils/utils.php
> ===================================================================
> --- include/utils/utils.php    (revision 14165)
> +++ include/utils/utils.php    (working copy)
> @@ -326,17 +326,29 @@
>      $log->debug("Exiting set_default_config method ...");
>  }
>
> -$toHtml = array(
> -        '"' => '"',
> -        '<' => '<',
> -        '>' => '>',
> -        '& ' => '& ',
> -        "'" =>  ''',
> -    '' => '\r',
> -        '\r\n'=>'\n',
> +//this is an optimisation of the to_html function, here we make the
> decision
> +//decide once if we are going to convert things to html
>
> -);
> +function decide_to_html(){
> +    global $doconvert;
> +    $action = $_REQUEST['action'];
> +    $search = $_REQUEST['search'];
> +    if($_REQUEST['module'] != 'Settings' && $_REQUEST['file'] !=
> 'ListView' && $_REQUEST['module'] != 'Portal' && $_REQUEST['module'] !=
> "Reports")// && $_REQUEST['module'] != 'Emails')
> +        $ajax_action = $_REQUEST['module'].'Ajax';
>
> +    if($action != 'CustomView' && $action != 'Export' && $action !=
> $ajax_action && $action != 'LeadConvertToEntities' && $action !=
> 'CreatePDF' && $action != 'ConvertAsFAQ' && $_REQUEST['module'] !=
> 'Dashboard' && $action != 'CreateSOPDF' && $action != 'SendPDFMail' &&
> (!isset($_REQUEST['submode'])) )
> +    {
> +        $doconvert = true;
> +    }
> +    else if($search == true)
> +    {
> +        // Fix for tickets #4647, #4648. Conversion required in case of
> search results also.
> +        $doconvert = true;
> +    }
> +
> +}
> +decide_to_html();//call the function once when loading
> +
>  /** Function to convert the given string to html
>    * @param $string -- string:: Type string
>    * @param $ecnode -- boolean:: Type boolean
> @@ -345,47 +357,15 @@
>         */
>  function to_html($string, $encode=true)
>  {
> -    global $log,$default_charset;
> -    //$log->debug("Entering to_html(".$string.",".$encode.") method
> ...");
> -    global $toHtml;
> -    $action = $_REQUEST['action'];
> -    $search = $_REQUEST['search'];
> -
> -    $doconvert = false;
> -
> -    // For optimization - default_charset can be either upper / lower
> case.
> -    static $inUTF8 = NULL;
> -    if ($inUTF8 === NULL) {
> -        $inUTF8 = (strtoupper($default_charset) == 'UTF-8');
> +    global $doconvert;
> +    global $default_charset;
> +        if($doconvert){
> +        return htmlentities($string, ENT_QUOTES, $default_charset);//we
> don't care if it is a string or not, faster not to care
> +    }else{
> +        return $string;
>      }
>
> -    if($_REQUEST['module'] != 'Settings' && $_REQUEST['file'] !=
> 'ListView' && $_REQUEST['module'] != 'Portal' && $_REQUEST['module'] !=
> "Reports")// && $_REQUEST['module'] != 'Emails')
> -        $ajax_action = $_REQUEST['module'].'Ajax';
>
> -    if(is_string($string))
> -    {
> -        if($action != 'CustomView' && $action != 'Export' && $action !=
> $ajax_action && $action != 'LeadConvertToEntities' && $action !=
> 'CreatePDF' && $action != 'ConvertAsFAQ' && $_REQUEST['module'] !=
> 'Dashboard' && $action != 'CreateSOPDF' && $action != 'SendPDFMail' &&
> (!isset($_REQUEST['submode'])) )
> -        {
> -            $doconvert = true;
> -        }
> -        else if($search == true)
> -        {
> -            // Fix for tickets #4647, #4648. Conversion required in case
> of search results also.
> -            $doconvert = true;
> -        }
> -
> -        // In vtiger5 ajax request are treated specially and the data is
> encoded
> -        if ($doconvert == true)
> -        {
> -            if($inUTF8)
> -                $string = htmlentities($string, ENT_QUOTES,
> $default_charset);
> -            else
> -                $string = preg_replace(array('/</', '/>/', '/"/'),
> array('<', '>', '"'), $string);
> -        }
> -    }
> -
> -    //$log->debug("Exiting to_html method ...");
> -    return $string;
>  }
>
>  /** Function to get the tablabel for a given id
>
> --
> Libertus Solutions
> http://libertus.co.uk
>
> _______________________________________________
> http://www.vtiger.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140717/1acdf8f9/attachment.html>


More information about the vtigercrm-developers mailing list