Reputation: 344
In an attempt to implement wrappers for parts of the CGAL library I have run into some performance issues. Some of it seems to be linked to C++/CLI interop. In an effort to identify the issue I have created a simple example, making a few calls to the some of the parts CGAL I want to wrap. I don't think the specific calls are super important to the issue, but i included it for reference. My program looks as follows:
std::ifstream stream1("Sphere1.OFF");
std::ifstream stream2("Sphere2.OFF");
Polyhedron P1 = Polyhedron();
Polyhedron P2 = Polyhedron();
stream1 >> P1;
stream2 >> P2;
Nef_polyhedron N1(P1);
Nef_polyhedron N2(P2);
Nef_polyhedron N3 = N1 + N2;
Polyhedron and Nef_polyhedron are CGAL types defined as:
typedef CGAL::Simple_cartesian<CGAL::Lazy_exact_nt<CGAL::Gmpq> > Kernel;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
If I simply run the program compiling without CLR support it runs in around 10 seconds. This is not ideal, but will have to do for now. The problem is that if i enable CLR support the time to run this small sample program triples to over 30 seconds.
I suspect the issue has something to do with CGAL being largely implemented as header only. Thus, Kernel, Polyhedron and Nef_polyhedron are compiled with CLR support, making it unpredictable how often interop calls take place. The idea was that the Nef_polyhedron N3 = N1 + N2;
call should be a single interop call to native code to reduce the overhead.
I tried using #pragma managed(push,off)
, to force native compilation of the header, but this just redoubled the execution time to around 70 seconds
Why am i getting such a big performance hit with CLR? Might it have something to do with marshalling of the Polyhedron and Nef_polyhedron types? And if so, would it help to specify at marshalling for these types?
Upvotes: 2
Views: 184