Commit 355fd8d5 authored by StefanBruens's avatar StefanBruens Committed by Albert Astals Cid

SplashXPathScanner: Optionally use small_vector from boost

Currently, each row in the intersections vector is allocated separately,
when the first intersection is added.

To avoid these allocations for common simple polygons,
boost::container::small_vector<4, T> is used, which stores up to
4 intersections inline. small_vector is a header-only class.

For the documents from #57 (fdo#96728) and #24 (fdo#78728), the
runtime/memory is significantly reduced (according to /usr/bin/time -v):
(1) $> pdftoppm -r 18 -aa no runsforever-poppler.pdf
(2) $> pdftoppm surf-types.pdf

Before/After
                                  runsforever-poppler |   surf-types
User time (seconds):                2348.08 / 1773.53 |   7.76 /  5.02
Maximum resident set size (kbytes):   46288 /   45896 |  14076 / 13748
parent 3348f4d3
......@@ -286,6 +286,14 @@ if(LCMS2_FOUND)
include_directories(SYSTEM ${LCMS2_INCLUDE_DIR})
endif()
if(ENABLE_SPLASH)
find_package(Boost 1.58.0)
if(Boost_FOUND)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(USE_BOOST_HEADERS ON)
endif()
endif()
# Recent versions of poppler-data install a .pc file.
# Use it to determine the encoding data path, if available.
# Default to the same prefix otherwise.
......@@ -730,6 +738,7 @@ show_end_message_yesno("use nss3" ENABLE_NSS3)
show_end_message_yesno("use curl" ENABLE_LIBCURL)
show_end_message_yesno("use libopenjpeg2" WITH_OPENJPEG)
show_end_message_yesno("use lcms2" USE_CMS)
show_end_message_yesno("use boost" Boost_FOUND)
show_end_message_yesno("command line utils" ENABLE_UTILS)
show_end_message_yesno("fuzz target" ENABLE_FUZZER)
show_end_message("test data dir" ${TESTDATADIR})
......@@ -762,6 +771,10 @@ if(NOT HAVE_JPX_DECODER)
message("Warning: You're not compiling any JPX decoder. Some files will fail to display properly.")
endif()
if(ENABLE_SPLASH AND NOT Boost_FOUND)
message("Warning: Use of boost is recommended for better performance.")
endif()
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${POPPLER_VERSION})
add_custom_target(dist
COMMAND
......
......@@ -18,6 +18,7 @@
// Copyright (C) 2016 Tor Lillqvist <tml@collabora.com>
// Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2018 Stefan Brüns <stefan.bruens@rwth-aachen.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -115,6 +116,11 @@
#cmakedefine USE_CMS 1
#endif
/* Use header-only classes from Boost in the Splash backend */
#ifndef USE_BOOST_HEADERS
#cmakedefine USE_BOOST_HEADERS 1
#endif
//------------------------------------------------------------------------
// version
//------------------------------------------------------------------------
......
......@@ -344,9 +344,11 @@ bool SplashXPathScanner::addIntersection(double segYMin, double segYMax,
}
auto& line = allIntersections[y - yMin];
#ifndef USE_BOOST_HEADERS
if (line.empty()) {
line.reserve(4);
}
#endif
line.push_back(intersect);
return true;
......
......@@ -25,6 +25,12 @@
#include "SplashTypes.h"
#include <poppler-config.h>
#ifdef USE_BOOST_HEADERS
#include <boost/container/small_vector.hpp>
#endif
#include <vector>
class SplashXPath;
......@@ -94,7 +100,11 @@ private:
int xMin, yMin, xMax, yMax;
bool partialClip;
#ifdef USE_BOOST_HEADERS
typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
#else
typedef std::vector<SplashIntersect> IntersectionLine;
#endif
std::vector<IntersectionLine> allIntersections;
friend class SplashXPathScanIterator;
......@@ -109,7 +119,11 @@ public:
bool getNextSpan(int *x0, int *x1);
private:
#ifdef USE_BOOST_HEADERS
typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
#else
typedef std::vector<SplashIntersect> IntersectionLine;
#endif
const IntersectionLine &line;
size_t interIdx; // current index into <line>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment