Getting the best out of C++ #48
Replies: 2 comments 1 reply
-
I am rather puzzled by this post and the question it asks. First of all, what would be the real advantages of turning Clipper2 into a header template library? Type agnostic coordinates sound great at first glance. Yet, you did write that all the underlying math had to be done with integers to ensure robustness, so any other kind of input has to be converted anyway. And what would be the performance gains mentioned? The only thing I can think of is that ClipperBase::AddPaths() could internally read the user's custom type and write the Vertex and LocalMinima structs right away, without having to go through TransformPaths<double, int64_t> as the current code. Sure, that's great, but there are other, elegant ways to solve this without turning the whole thing into a template header. I don't really see other benefits to this desired conversion. Am I missing something? And the drawbacks? As you mentioned, it would be a lot harder to read and understand, even for the guy who wrote it. The meat of the code will be hidden by C++'s latest fancy bells and whistles. And it's not really going to be usable from other programming languages ("clean" C++ can be called from many languages, and if not, just put a C interface on top ~ everything can call C). I wouldn't have understood and rewrote a complicated C++ template header in C in a few days (as intermediate step, CUDA is still the end goal). In fact, I wouldn't even have bothered trying to understand the code. If you want performance, I would suggest we put the time into improving the scalability of the algorithm. Then I'll get performance out of C (SSE/AVX/AVX512 intrinsics, perhaps threads, NUMA awareness, etc.) and hopefully CUDA (I'm hoping I can transform the C version into something with decent parallelism). Just my two cents. 😜 |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, |
Beta Was this translation helpful? Give feedback.
-
There's little doubt that well written C++ code is unrivalled in performance, at least by other high level languages. So why isn't everyone writing C++ code? Personally I'm put off C++ because it can be so complicated. And hard to read code is hard to maintain, even by the person that wrote it. But C++ doesn't have to be complicated. Clipper2's current C++ code is just about as easy to read as the C# and Delphi code, and still comfortably out performs both of them.
So, what's this post all about?
Vojtěch Bubník is in the process of converting Clipper2 C++ into a (mostly?) header template library. And I'm mostly very enthusiastic about this, and confident that Vojtěch's conversion will make the library more flexible (eg type agnostic coordinates) and further improve performance. However, this will come at a cost. And I've had feedback from a couple of people hinting that they have at least mild reservations.
So what are the downsides? Why not get the best out of C++'s newer features (ie templates with traits, concepts, predicates etc)? Firstly, the code will be more complex, though I anticipate this will be obscured by well designed instances of these new template classes. And given that I'm going to maintain the C++ code, I'll need to gain at least a working knowledge of these new features before they can replace my current translation. (And that will take a little time as I'm certainly not an experienced C++ coder.) Also, Vojtěch's new code will require C++17 (or later versions). And finally, those wanting to fork the library to tweak to their own requirements may not appreciate this added complexity.
Both Vojtěch and I would value your thoughts, comments or suggestions on this.
Edit: One possibility might be to retain a simple C++ translation here and also publish links to well constructed and maintained forks.
Beta Was this translation helpful? Give feedback.
All reactions