[gtk-doc] Substantial performance improvements



commit 402b4973e847120aa5771dbeb613805f3b9663fb
Author: Shaun McCance <shaunm gnome org>
Date:   Sat Aug 13 08:30:11 2011 -0400

    Substantial performance improvements
    
    Changes made to areas that xsltproc --profile indicated were eating
    up the most time. Most changes are to use xsl:key to avoid frequent
    descendant selectors. In one case there's a slightly hacking XPath
    change that has a significant performance impact. Testing on the
    GTK+ docs, I got about a 40% speed gain.

 devhelp2.xsl       |    2 ++
 gtk-doc-single.xsl |   19 ++++++++++++++++---
 gtk-doc.xsl        |   40 ++++++++++++++++++++++++++++++----------
 3 files changed, 48 insertions(+), 13 deletions(-)
---
diff --git a/devhelp2.xsl b/devhelp2.xsl
index b183e9a..76a20b7 100644
--- a/devhelp2.xsl
+++ b/devhelp2.xsl
@@ -27,6 +27,8 @@
     </xsl:call-template>
   </xsl:template>
 
+  <xsl:variable name="gtkdoc.refsect2" select="//refsect2"/>
+
   <xsl:template name="devhelp2">
     <xsl:variable name="title">
       <xsl:apply-templates select="." mode="generate.devhelp2.toc.title.mode"/>
diff --git a/gtk-doc-single.xsl b/gtk-doc-single.xsl
index 9045af1..bbc5f26 100644
--- a/gtk-doc-single.xsl
+++ b/gtk-doc-single.xsl
@@ -6,6 +6,13 @@
   <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
   <xsl:include href="version-greater-or-equal.xsl"/>
 
+  <xsl:key name="acronym.key"
+	   match="glossentry/glossterm"
+	   use="."/>
+  <xsl:key name="gallery.key"
+	   match="para[ role='gallery']/link"
+	   use="@linkend"/>
+
   <!-- change some parameters -->
   <xsl:param name="toc.section.depth">2</xsl:param>
   <xsl:param name="generate.toc">
@@ -62,7 +69,13 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
         <xsl:apply-templates select="//releaseinfo/ulink"
                              mode="generate.index.mode"/>
         <!-- check all anchor and refentry elements -->
-        <xsl:apply-templates select="//anchor|//refentry|//refsect1|//refsect2|//refsynopsisdiv"
+	<!--
+	    The obvious way to write this is //anchor|//refentry|etc...
+	    The obvious way is slow because it causes multiple traversals
+	    in libxslt. This take about half the time.
+	-->
+	<xsl:apply-templates select="//*[name()='anchor' or name()='refentry' or name()='refsect1' or
+				         name() = 'refsect2' or name()='refsynopsisdiv']"
                              mode="generate.index.mode"/>
       </xsl:with-param>
       <xsl:with-param name="default.encoding" select="'UTF-8'"/>
@@ -503,7 +516,7 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
                 - use it here
              -->
            <xsl:variable name="refentryid" select="../@id"/>
-           <xsl:apply-templates select="//para[ role = 'gallery']/link[ linkend = $refentryid]/inlinegraphic"/>
+	   <xsl:apply-templates select="key('gallery.key', $refentryid)/inlinegraphic"/>
         </td></tr>
        </table>
      </div>
@@ -529,7 +542,7 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
     -->
    
     <xsl:param name="value" >
-      <xsl:value-of select="//glossentry/glossterm[text()=$acronym]/../glossdef/para[1]" />
+      <xsl:value-of select="key('acronym.key', $acronym)/../glossdef/para[1]" />
     </xsl:param>
     <xsl:choose>
       <xsl:when test="$value=''">
diff --git a/gtk-doc.xsl b/gtk-doc.xsl
index 5eddb4f..36b6453 100644
--- a/gtk-doc.xsl
+++ b/gtk-doc.xsl
@@ -11,6 +11,13 @@
   <xsl:include href="devhelp2.xsl"/>
   <xsl:include href="version-greater-or-equal.xsl"/>
 
+  <xsl:key name="acronym.key"
+	   match="glossentry/glossterm"
+	   use="."/>
+  <xsl:key name="gallery.key"
+	   match="para[ role='gallery']/link"
+	   use="@linkend"/>
+
   <!-- change some parameters -->
   <!-- http://docbook.sourceforge.net/release/xsl/current/doc/html/index.html -->
   <xsl:param name="toc.section.depth">2</xsl:param>
@@ -61,11 +68,18 @@
 
   <xsl:param name="gtkdoc.l10n.xml" select="document('http://docbook.sourceforge.net/release/xsl/current/common/en.xml')"/>
 
+  <xsl:key name="gtkdoc.gentext.key"
+	   match="l:gentext[ key]"
+	   use="@key"/>
+  <xsl:key name="gtkdoc.context.key"
+	   match="l:context[ name]"
+	   use="@name"/>
+
   <xsl:template name="gentext">
     <xsl:param name="key" select="local-name(.)"/>
 
-    <xsl:variable name="l10n.gentext"
-                  select="($gtkdoc.l10n.xml/l:l10n/l:gentext[ key=$key])[1]"/>
+    <xsl:for-each select="$gtkdoc.l10n.xml">
+    <xsl:variable name="l10n.gentext" select="key('gtkdoc.gentext.key', $key)"/>
 
     <xsl:choose>
       <xsl:when test="$l10n.gentext">
@@ -79,6 +93,7 @@
         </xsl:message>
       </xsl:otherwise>
     </xsl:choose>
+    </xsl:for-each>
   </xsl:template>
 
   <xsl:template name="gentext.dingbat">
@@ -128,9 +143,8 @@
     see html/html.xsl:<xsl:template match="*" mode="html.title.attribute">
     -->
 
-    <xsl:variable name="context.node"
-                  select="$gtkdoc.l10n.xml/l:l10n/l:context[ name=$context]"/>
-
+    <xsl:for-each select="$gtkdoc.l10n.xml">
+    <xsl:variable name="context.node" select="key('gtkdoc.context.key', $context)"/>
     <xsl:variable name="template.node"
                   select="($context.node/l:template[ name=$rname])[1]"/>
 
@@ -155,6 +169,7 @@
         </xsl:choose>
       </xsl:otherwise>
     </xsl:choose>
+    </xsl:for-each>
   </xsl:template>
 
   <!-- silently test whether a gentext template exists -->
@@ -278,8 +293,6 @@
   <!-- ========================================================= -->
   <!-- template to create the index.sgml anchor index -->
 
-  <xsl:param name="gtkdoc.refsect2" select="//refsect2" />
-
   <xsl:template match="book|article">
     <xsl:variable name="tooldver">
       <xsl:call-template name="version-greater-or-equal">
@@ -309,7 +322,14 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
         <xsl:apply-templates select="/book/bookinfo/releaseinfo/ulink"
                              mode="generate.index.mode"/>
         <!-- check all anchor and refentry elements -->
-        <xsl:apply-templates select="//anchor|//refentry|//refsect1|$gtkdoc.refsect2|//refsynopsisdiv|//varlistentry"
+	<!--
+	    The obvious way to write this is //anchor|//refentry|etc...
+	    The obvious way is slow because it causes multiple traversals
+	    in libxslt. This take about half the time.
+	-->
+	<xsl:apply-templates select="//*[name()='anchor' or name()='refentry' or name()='refsect1' or
+				         name() = 'refsect2' or name()='refsynopsisdiv' or
+					 name()='varlistentry']"
                              mode="generate.index.mode"/>
       </xsl:with-param>
       <xsl:with-param name="default.encoding" select="'UTF-8'"/>
@@ -777,7 +797,7 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
                    - use it here
                 -->
               <xsl:variable name="refentryid" select="../@id"/>
-              <xsl:apply-templates select="//para[ role = 'gallery']/link[ linkend = $refentryid]/inlinegraphic"/>
+	      <xsl:apply-templates select="key('gallery.key', $refentryid)/inlinegraphic"/>
             </xsl:otherwise>
           </xsl:choose>
         </td></tr>
@@ -849,7 +869,7 @@ Get a newer version at http://docbook.sourceforge.net/projects/xsl/
     -->
 
     <xsl:param name="value" >
-      <xsl:value-of select="//glossentry/glossterm[text()=$acronym]/../glossdef/para[1]" />
+      <xsl:value-of select="key('acronym.key', $acronym)/../glossdef/para[1]" />
     </xsl:param>
     <xsl:choose>
       <xsl:when test="$value=''">



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