[Vtigercrm-developers] Fwd: Fwd: performance and profiling
Vic Cekvenich
vic.cvc at gmx.com
Mon Aug 18 00:40:48 GMT 2014
-------- Original Message --------
Subject: [Vtigercrm-developers] Fwd: performance and profiling
Date: Sun, 17 Aug 2014 15:01:08 -0700
From: Vic Cekvenich <vic.cvc at gmx.com>
Reply-To: vtigercrm-developers at lists.vtigercrm.com
To: vtigercrm-developers at lists.vtigercrm.com
-------- Original Message --------
Subject: [Vtigercrm-developers] performance and profiling
Date: Thu, 17 Jul 2014 15:14:43 +0100
From: Alan Bell <alan.bell at libertus.co.uk>
Reply-To: vtigercrm-developers at lists.vtigercrm.com
To: vtigercrm-developers at lists.vtigercrm.com <vtigercrm-developers at lists.vtigercrm.com>
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/
_______________________________________________
http://www.vtiger.com/
More information about the vtigercrm-developers
mailing list