SPARQL XML to HTML XSL Performance Bug

All,

I've discovered a performance bug in the xml-to-html.xsl stylesheet [1] in
the "SPARQL Query Results XML Format" recommendation [2]. This XSL is used
to transform SPARQL result queries into XHTML. The effect is not so great on
small result sets (10's), but has a pretty significant effect for larger
result sets (1000's).

The bug occurs when the XSL is iterating over the bindings in each <result>
tag. The variables are selected using the xpath expression
"//res:head/res:variable", which forces a search over all of the nodes in
the document to find a match for "res:head/res:variable". This is quite slow
as it scales with the size of the document.

Since the SPARQL XML result format specifies that the "res:head" elements is
on the "res:sparql" element which is directly on the root, we can replace
the previous xpath expression with "/res:sparql/res:head/res:variable" and
gain a significant speed increase (no need to search the entire document).

Just as a single data point, I am seeing the rendering time in Firefox for a
modest 3,000 entity result set drop from 40 seconds to 5 seconds with the
fix.

The XML Query Results recommendation is included by reference in the SPARQL
1.1 Query working draft but is itself not being updated for SPARQL 1.1,
therefore I am not sure if this counts as a comment on the 1.1 draft.

I've attached a patch inline at the end of this email.

Best Regards,
Stephen Allen

[1] http://www.w3.org/TR/rdf-sparql-XMLres/result-to-html.xsl
[2] http://www.w3.org/TR/rdf-sparql-XMLres/



--- C:\SPARQL\result-to-html.xsl.orig	2011-07-15 10:23:40.000000000 -0400
+++ C:\SPARQL\result-to-html.xsl	2011-07-15 10:26:42.000000000 -0400
@@ -83,13 +83,13 @@
       </table>
     </div>
   </xsl:template>
 
   <xsl:template match="res:result">
     <xsl:variable name="current" select="."/>
-    <xsl:for-each select="//res:head/res:variable">
+    <xsl:for-each select="/res:sparql/res:head/res:variable">
       <xsl:variable name="name" select="@name"/>
       <td>
 	<xsl:choose>
 	  <xsl:when test="$current/res:binding[@name=$name]">
 	    <!-- apply template for the correct value type (bnode, uri,
 	    literal) -->

Received on Saturday, 16 July 2011 11:33:33 UTC