[Libreoffice-commits] core.git: sax/source writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jul 17 11:27:25 UTC 2018


 sax/source/fastparser/fastparser.cxx     |   17 ++++++++++++-----
 writerfilter/source/ooxml/factoryimpl.py |    6 ++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

New commits:
commit d6bd9c273483b12f1bb2ae398afdba977e3ec336
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jul 17 09:49:55 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jul 17 13:27:02 2018 +0200

    tdf#79878 perf loading docx file, disable SAX threading for writer
    
    since it seems to cost us 20% performance
    
    Change-Id: Ic4796ee3756c8c722feb4851dc48a99e882ba0fe
    Reviewed-on: https://gerrit.libreoffice.org/57545
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 83b36d122f42..4ae2f4fdaf4a 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -247,6 +247,7 @@ public:
     void parse();
     void produce( bool bForceFlush = false );
     bool m_bIgnoreMissingNSDecl;
+    bool m_bDisableThreadedParser;
 
 private:
     bool consume(EventList&);
@@ -634,6 +635,7 @@ namespace sax_fastparser {
 
 FastSaxParserImpl::FastSaxParserImpl() :
     m_bIgnoreMissingNSDecl(false),
+    m_bDisableThreadedParser(false),
     mpTop(nullptr)
 {
     mxDocumentLocator.set( new FastLocatorImpl( this ) );
@@ -781,7 +783,7 @@ void FastSaxParserImpl::parseStream(const InputSource& rStructSource)
         rEntity.mxDocumentHandler->startDocument();
     }
 
-    if (!getenv("SAX_DISABLE_THREADS"))
+    if (!getenv("SAX_DISABLE_THREADS") && !m_bDisableThreadedParser)
     {
         Reference<css::io::XSeekable> xSeekable(rEntity.maStructSource.aInputStream, UNO_QUERY);
         // available() is not __really__ relevant here, but leave it in as a heuristic for non-seekable streams
@@ -1325,11 +1327,16 @@ FastSaxParser::initialize(css::uno::Sequence< css::uno::Any > const& rArguments)
     if (rArguments.getLength())
     {
         OUString str;
-        if ( ( rArguments[0] >>= str ) && "IgnoreMissingNSDecl" == str )
-            mpImpl->m_bIgnoreMissingNSDecl = true;
-        else if ( str == "DoSmeplease" )
+        if ( rArguments[0] >>= str )
         {
-            //just ignore as this is already immune to billion laughs
+            if ( str == "IgnoreMissingNSDecl" )
+                mpImpl->m_bIgnoreMissingNSDecl = true;
+            else if ( str == "DoSmeplease" )
+                ; //just ignore as this is already immune to billion laughs
+            else if ( str == "DisableThreadedParser" )
+                mpImpl->m_bDisableThreadedParser = true;
+            else
+                throw IllegalArgumentException();
         }
         else
             throw IllegalArgumentException();
diff --git a/writerfilter/source/ooxml/factoryimpl.py b/writerfilter/source/ooxml/factoryimpl.py
index acbaf4234261..2d54ee8ff6b8 100644
--- a/writerfilter/source/ooxml/factoryimpl.py
+++ b/writerfilter/source/ooxml/factoryimpl.py
@@ -152,6 +152,11 @@ def getFastParser():
     if (!mxFastParser.is())
     {
         mxFastParser = css::xml::sax::FastParser::create(mxContext);
+        // the threaded parser is about 20% slower loading writer documents
+        css::uno::Reference< css::lang::XInitialization > xInit( mxFastParser, css::uno::UNO_QUERY_THROW );
+        css::uno::Sequence< css::uno::Any > args(1);
+        args[0] <<= OUString("DisableThreadedParser");
+        xInit->initialize(args);
 """)
     for url in sorted(ooxUrlAliases.keys()):
         print("""        mxFastParser->registerNamespace("%s", oox::NMSP_%s);""" % (url, ooxUrlAliases[url]))
@@ -167,6 +172,7 @@ def getFastParser():
 def createImpl(model):
     print("""
 #include <com/sun/star/xml/sax/FastParser.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
 #include "ooxml/OOXMLFactory.hxx"
 #include "ooxml/OOXMLFastHelper.hxx"
 #include "ooxml/OOXMLStreamImpl.hxx"


More information about the Libreoffice-commits mailing list