2

Since gcc 3.4.5 is used in the whole company, I have to use rtree of boost 1.57 because rtree of boost 1.59 has compile problem. I just use rtree in following way:

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef std::pair<box, size_t> value;

// create the rtree using default constructor
bgi::rtree<value, bgi::linear<500> > rtree;

// create some values
ifstream ifs(bbox_filename);
if (!ifs.is_open()) return;

std::vector<box> boxes;

boost::timer t;

// ... (read box from test file)

std::cout << "read bbox file: " << t.elapsed() << " sec." << std::endl;

t.restart();
for (size_t i = 0; i < boxes.size(); ++i)
{
    // insert new value
    rtree.insert(std::make_pair(boxes[i], i));
}
std::cout << "build rtree with " << boxes.size() << " boxes in total: " << t.elapsed() << " sec." << std::endl;

In my use case, the element number would be tens of millions, the query speed is fast and acceptable, but the speed of building rtree is very slow (O2 is enabled of course).

When I compiled the same test program with gcc 4.4.7 and compare the testing result , I found it's because of gcc version.

test environment:

CentOS 6.6
Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz

test log for gcc 4.4.7:

read bbox file: 22.13 sec.
build rtree with 42517937 boxes in total: 163.28 sec.

test log for gcc 3.4.5:

read bbox file: 22.28 sec.
build rtree with 42517937 boxes in total: 468.73 sec.

It seems test program compiled by gcc 3.4.5 takes about 3 times of time to build rtree than 4.4.7.

Is there anyone who met this problem before? Any advice to improve the performance under gcc 3.4.5? (I cannot choose compiler currently:()

genpfault
  • 51,148
  • 11
  • 85
  • 139
wpc062
  • 308
  • 2
  • 9
  • I think your best bet is going to be try and understand what 3.4.5 is doing wrong and fix your copy of rtree to avoid it. It's probably an optimisation to eliminate some copy either the pair or the `linear<500>` whilst assembling the tree. It might also be worth comparing 1.57 with the latest boost to see if there's any obvious improvements on its handling of references internally that would be worth working through the compile errors for. You could also try getting things working with templating the rtree on pointers to the objects, but that's less C++ and likely tricky too. – Rup May 06 '16 at 09:38
  • 4
    That said GCC 3.4.5 is [over ten years old](https://gcc.gnu.org/gcc-3.4/). It'd definitely be worth raising updating with the powers that be in your company, and giving them this as an example why newer versions do C++ better. (assuming newer versions 'just work' with your codebases) – Rup May 06 '16 at 09:41
  • @Rup, Thanks for your reply. I also compiled the test program with boost 1.59 and gcc 4.4.7. Its performance is comparable with boost 1.57 and gcc 4.4.7. There is no dramatic improvement. – wpc062 May 06 '16 at 09:53
  • OK, that sounds like a dead-end then. There's still a faint chance that 1.59 on 3.4.5 would work better if its rtree implementation avoids extra copies using older-C++-compatible methods, but it probably doesn't. – Rup May 06 '16 at 09:56
  • 1
    One possible cause is that gcc 4 has support for rvalue references, and *might* generate some move assignment or move constructors. – Bo Persson May 06 '16 at 10:33

1 Answers1

4

Thanks for everyone's help and the post packing algorithm in rtree in boost.

After using packing algorithm (range constructor), the performance of building rtree is improved greatly.

std::vector<value> boxes;

boost::timer t;

// ... (read box from test file)

std::cout << "read bbox file: " << t.elapsed() << " sec." << std::endl;

t.restart();
bgi::rtree<value, bgi::linear<500> > rtree(boxes);
std::cout << "build rtree with " << boxes.size() << " boxes in total: " << t.elapsed() << " sec." << std::endl;

test log for gcc 4.4.7 + packing algorithm:

read bbox file: 23.07 sec.
build rtree with 42517937 boxes in total: 8.15 sec.

test log for gcc 3.4.5 + packing algorithm:

read bbox file: 23.06 sec.
build rtree with 42517937 boxes in total: 10.94 sec.

Now the runtime difference between gcc 3.4.5 and 4.4.7 is acceptable.

PS: During my test, the runtime of building rtree without O2 and packing algorithm could be 1000 times slower. Hope this post could give someone who uses boost::rtree later some hint.

Community
  • 1
  • 1
wpc062
  • 308
  • 2
  • 9