Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-2349

Improve performance of AttributeFilter in HTMLCleaner

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 13.10.2
    • XML
    • Unknown

    Description

      While investigating XWIKI-19314 I found that calling XPathFactory.newInstance() is really bad for performance as it uses the class loader to search for possible factory implementations. This is probably the root cause why the performance tests with the 1000 HTML macros are much slower than with 1000 id macros (roughly factor 10). The AttributeFilter calls this method whenever a new HTML document is cleaned which happens for every use of the HTML macro. The main problem is that neither the factory nor the XPath nor XPathExpression are thread-safe, so we cannot just statically initialize those and re-use those. A possible fix is to use a ThreadLocal to have an instance per thread. This may cause memory leaks though if we never remove them and the application server continues running after XWiki is stopped. There could be the possibility to use either the execution context to store the data or to use a mechanism similar to the execution context to remove the data (or introduce a generic mechanism to register thread locals that should be removed since we already have existing ThreadLocal variables that suffer from the same issue).

      We should also investigate other uses of XPathFactory.newInstance(), I have already found several uses in the XML/HTML diff but I don't know how severe their impact is.

      Attachments

        Activity

          People

            MichaelHamann Michael Hamann
            MichaelHamann Michael Hamann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: