开发者

XQSharp XSLT2 performance tuning

I have a real time application that uses XSLT1 and i want to upgrade to XSLT2. Currently i am using microsoft xslt1 engine that performs for a specific xml and xsl within 0.1 second.

For XSLT2 transformation i created a function that uses XQSharp to perform xslt2 transformation. I used the same xml and xsl and the transformation took 0.9 second.

I analyzed my code and it turns out that more then 90% of the processing time is caused by this line :

Dim query As Xslt = Xslt.Compile(New StringReader(in开发者_JAVA技巧putXsl), querySettings)

My question is of there is a way to speed up this process ?

For example by changing some querySettings?

My full code

   <WebMethod()> _
    Public Function XSLTXQSharp(ByVal inputXml As String, ByVal inputXsl As String) As String
        Dim nameTable As XmlNameTable = New NameTable()

        Dim xmlReaderSettings As New XmlReaderSettings()
        xmlReaderSettings.NameTable = nameTable

        Dim document As XdmDocument

        Using reader As New StringReader(inputXml)
            Using xmlReader As XmlReader = xmlReader.Create(reader, xmlReaderSettings)
                document = New XdmDocument(xmlReader)
            End Using
        End Using


        Dim querySettings As New XsltSettings(nameTable)
        querySettings.ContextItemType = XdmType.Node
        querySettings.ModuleResolver = New XmlUrlResolver()


        ''' SLOW!!! more then 90 % of execution time
        Dim query As Xslt = Xslt.Compile(New StringReader(inputXsl), querySettings)

        Dim contextItem As XPathNavigator = document.CreateNavigator()
        Dim result As Stream = New MemoryStream()
        query.ApplyTemplates(contextItem, result)

        'Return dt2.Subtract(dt1).ToString()

        result.Position = 0
        Using reader As StreamReader = New StreamReader(result)
            Return reader.ReadToEnd()
        End Using


    End Function


Try changing the optimization level. It's a property on the static context settings. It would be helpful to see the transformation you are trying to compile.

Note that the Microsoft compiler is pretty quick, and it compiles to byte code. XQSharp tends to win with more complex stylesheets, or where XSLT 2.0 features (e.g. for-each-group) are replacing use of keys in XSLT 1.0.


You may find you need to use a forum specific to XQSharp for this one.

Is this a case where a large and complex stylesheet is being used to transform a small source document?

Is there no way you can amortize the cost of compiling the stylesheet and then caching the result to use for many transformations? Quite often developers will assume that time spent optimizing the code during compilation is well spent if it reduces run-time execution time - which doesn't seem to be true the way this workload is written.

From a purely selfish perspective I'd be quite interested to know how the numbers compare with Saxon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜