W3C home > Mailing lists > Public > public-rdf-dawg-comments@w3.org > July 2011

SPARQL XML to HTML XSL Performance Bug

From: Stephen Allen <sallen@bbn.com>
Date: Fri, 15 Jul 2011 11:20:20 -0400
To: <public-rdf-dawg-comments@w3.org>
Message-ID: <019a01cc4302$b5e0dcb0$21a29610$@com>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 16 July 2011 11:33:34 GMT