mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
doc: Speed up XSLT builds
The upstream XSLT stylesheets use some very general XPath expressions in some places that end up being very slow. We can optimize them with knowledge about the DocBook document structure and our particular use thereof. For example, when counting preceding chapters to get a number for the current chapter, we only need to count preceding sibling nodes (more or less) instead of searching through the entire node tree for chapter elements. This change attacks the slowest pieces as identified by xsltproc --profile. This makes the HTML build roughly 10 times faster, resulting in the new total build time being about the same as the old DSSSL-based build. Some of the non-HTML build targets (especially FO) will also benefit a bit, but they have not been specifically analyzed. With this, also remove the pg.fast parameter, which was previously a hack to get the build to a manageable speed. Alexander Lakhin <a.lakhin@postgrespro.ru>, with some additional tweaking by me
This commit is contained in:
94
doc/src/sgml/stylesheet-speedup-common.xsl
Normal file
94
doc/src/sgml/stylesheet-speedup-common.xsl
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version='1.0'>
|
||||
|
||||
<!-- Performance-optimized versions of some upstream templates from common/
|
||||
directory -->
|
||||
|
||||
<!-- from common/labels.xsl -->
|
||||
|
||||
<xsl:template match="chapter" mode="label.markup">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@label">
|
||||
<xsl:value-of select="@label"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="string($chapter.autolabel) != 0">
|
||||
<xsl:if test="$component.label.includes.part.label != 0 and
|
||||
ancestor::part">
|
||||
<xsl:variable name="part.label">
|
||||
<xsl:apply-templates select="ancestor::part"
|
||||
mode="label.markup"/>
|
||||
</xsl:variable>
|
||||
<xsl:if test="$part.label != ''">
|
||||
<xsl:value-of select="$part.label"/>
|
||||
<xsl:apply-templates select="ancestor::part"
|
||||
mode="intralabel.punctuation">
|
||||
<xsl:with-param name="object" select="."/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
<xsl:variable name="format">
|
||||
<xsl:call-template name="autolabel.format">
|
||||
<xsl:with-param name="format" select="$chapter.autolabel"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$label.from.part != 0 and ancestor::part">
|
||||
<xsl:number from="part" count="chapter" format="{$format}" level="any"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- Optimization for pgsql-docs: When counting to get label for
|
||||
this chapter, preceding chapters can only be our siblings or
|
||||
children of a preceding part, so only count those instead of
|
||||
scanning the entire node tree. -->
|
||||
<!-- <xsl:number from="book" count="chapter" format="{$format}" level="any"/> -->
|
||||
<xsl:number value="count(../preceding-sibling::part/chapter) + count(preceding-sibling::chapter) + 1" format="{$format}"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="appendix" mode="label.markup">
|
||||
<xsl:choose>
|
||||
<xsl:when test="@label">
|
||||
<xsl:value-of select="@label"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="string($appendix.autolabel) != 0">
|
||||
<xsl:if test="$component.label.includes.part.label != 0 and
|
||||
ancestor::part">
|
||||
<xsl:variable name="part.label">
|
||||
<xsl:apply-templates select="ancestor::part"
|
||||
mode="label.markup"/>
|
||||
</xsl:variable>
|
||||
<xsl:if test="$part.label != ''">
|
||||
<xsl:value-of select="$part.label"/>
|
||||
<xsl:apply-templates select="ancestor::part"
|
||||
mode="intralabel.punctuation">
|
||||
<xsl:with-param name="object" select="."/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:if>
|
||||
</xsl:if>
|
||||
<xsl:variable name="format">
|
||||
<xsl:call-template name="autolabel.format">
|
||||
<xsl:with-param name="format" select="$appendix.autolabel"/>
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$label.from.part != 0 and ancestor::part">
|
||||
<xsl:number from="part" count="appendix" format="{$format}" level="any"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- Optimization for pgsql-docs: When counting to get label for
|
||||
this appendix, preceding appendixes can only be our siblings or
|
||||
children of a preceding part, so only count those instead of
|
||||
scanning the entire node tree. -->
|
||||
<!-- <xsl:number from="book|article" count="appendix" format="{$format}" level="any"/> -->
|
||||
<xsl:number value="count(../preceding-sibling::part/appendix) + count(preceding-sibling::appendix) + 1" format="{$format}"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
Reference in New Issue
Block a user