[xslt] likely/unlikely hinting for libxml/libxslt



hi,

in the quest of figuring our what canb be done to make gtk-doc less slow
(where the only slow part is the docbook xslt processing) I was running
it under oprofile and studying the report. Below is the profile
(probably nothing new in there). Attached is also the callgraph as an
image (not sure if that will get through to the list).

Some questions:

* I'd suggest to make use of __builtin_expect() in libxml. glib does:

#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define G_LIKELY(expr) (__builtin_expect ((expr), 1))
#define G_UNLIKELY(expr) (__builtin_expect ((expr), 0))
#else
#define G_LIKELY(expr) (expr)
#define G_UNLIKELY(expr) (expr)
#endif

Could that be added to libxml as e.g. XML_{UN,}LIKELY? It could be used
e.g. in xpathInternals.h, e.g. for

#define CHECK_ERROR                            \
    if (XML_UNLIKELY (ctxt->error != XPATH_EXPRESSION_OK)) return

With the attached (hackish patch) I got the % for xmlXPathCompOpEval
from 22.69% down to 17.70%.
(this was just on, but one long iteration).

If there is no one against such an approach I can make a proper patch
and submit it to bugzilla.

Stefan


samples  %        image name               app name                
symbol name
240169   23.1481  no-vmlinux               no-vmlinux              
/no-vmlinux
73851     7.1179  oprofiled                oprofiled               
/usr/bin/oprofiled
43123     4.1563  libc-2.10.1.so           libc-2.10.1.so          
_int_malloc
39401     3.7976  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlStrEqual
39368     3.7944  perl                     perl                    
/usr/bin/perl
31196     3.0068  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlXPathNextChildElement
28655     2.7618  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlXPathReleaseObject
28102     2.7085  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlXPathNodeCollectAndTest
25979     2.5039  libc-2.10.1.so           libc-2.10.1.so           malloc
25202     2.4290  libc-2.10.1.so           libc-2.10.1.so          
_int_free
25108     2.4200  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlXPathCompOpEval
23579     2.2726  libc-2.10.1.so           libc-2.10.1.so           free
15834     1.5261  libc-2.10.1.so           libc-2.10.1.so           memcpy
13281     1.2801  libc-2.10.1.so           libc-2.10.1.so          
malloc_consolidate
11009     1.0611  Xorg                     Xorg                    
/usr/bin/Xorg
9680      0.9330  libxml2.so.2.7.6         libxml2.so.2.7.6        
valuePush
9309      0.8972  libxml2.so.2.7.6         libxml2.so.2.7.6        
xmlDictLookup

PNG image

diff --git a/include/libxml/xpathInternals.h b/include/libxml/xpathInternals.h
index dcd5243..b1a1da2 100644
--- a/include/libxml/xpathInternals.h
+++ b/include/libxml/xpathInternals.h
@@ -237,7 +237,7 @@ XMLPUBFUN void * XMLCALL
  * Macro to return from the function if an XPath error was detected.
  */
 #define CHECK_ERROR							\
-    if (ctxt->error != XPATH_EXPRESSION_OK) return
+    if (__builtin_expect ((ctxt->error != XPATH_EXPRESSION_OK), 0)) return
 
 /**
  * CHECK_ERROR0:
@@ -245,7 +245,7 @@ XMLPUBFUN void * XMLCALL
  * Macro to return 0 from the function if an XPath error was detected.
  */
 #define CHECK_ERROR0							\
-    if (ctxt->error != XPATH_EXPRESSION_OK) return(0)
+    if (__builtin_expect ((ctxt->error != XPATH_EXPRESSION_OK), 0)) return(0)
 
 /**
  * XP_ERROR:
@@ -273,7 +273,7 @@ XMLPUBFUN void * XMLCALL
  * type.
  */
 #define CHECK_TYPE(typeval)						\
-    if ((ctxt->value == NULL) || (ctxt->value->type != typeval))	\
+    if (__builtin_expect (((ctxt->value == NULL) || (ctxt->value->type != typeval)),0))	\
         XP_ERROR(XPATH_INVALID_TYPE)
 
 /**
@@ -284,7 +284,7 @@ XMLPUBFUN void * XMLCALL
  * type. Return(0) in case of failure
  */
 #define CHECK_TYPE0(typeval)						\
-    if ((ctxt->value == NULL) || (ctxt->value->type != typeval))	\
+    if (__builtin_expect (((ctxt->value == NULL) || (ctxt->value->type != typeval)),0))	\
         XP_ERROR0(XPATH_INVALID_TYPE)
 
 /**
@@ -294,8 +294,8 @@ XMLPUBFUN void * XMLCALL
  * Macro to check that the number of args passed to an XPath function matches.
  */
 #define CHECK_ARITY(x)							\
-    if (ctxt == NULL) return;						\
-    if (nargs != (x))							\
+    if (__builtin_expect ((ctxt == NULL),0)) return;						\
+    if (__builtin_expect ((nargs != (x)),0))							\
         XP_ERROR(XPATH_INVALID_ARITY);
 
 /**
@@ -304,7 +304,7 @@ XMLPUBFUN void * XMLCALL
  * Macro to try to cast the value on the top of the XPath stack to a string.
  */
 #define CAST_TO_STRING							\
-    if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING))	\
+    if (__builtin_expect (((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)),1))	\
         xmlXPathStringFunction(ctxt, 1);
 
 /**
@@ -313,7 +313,7 @@ XMLPUBFUN void * XMLCALL
  * Macro to try to cast the value on the top of the XPath stack to a number.
  */
 #define CAST_TO_NUMBER							\
-    if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER))	\
+    if (__builtin_expect (((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)),1))	\
         xmlXPathNumberFunction(ctxt, 1);
 
 /**
@@ -322,7 +322,7 @@ XMLPUBFUN void * XMLCALL
  * Macro to try to cast the value on the top of the XPath stack to a boolean.
  */
 #define CAST_TO_BOOLEAN							\
-    if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN))	\
+    if (__builtin_expect (((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)),1))	\
         xmlXPathBooleanFunction(ctxt, 1);
 
 /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]