-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Custom variant type #51
Conversation
Nice |
Cool stuff! Can we add support for cross-type comparisons, e.g. (std::string) "1" == (int) 1 == (double) 1? |
Yes, we should. Note to myself : https://www.inkling.com/read/javascript-definitive-guide-david-flanagan-6th/chapter-3/type-conversions |
We should make it obey the never empty guarantee, too. |
@DennisOSRM - yes, on my list, but not a trivial thing:) ^^ |
@artemp Cool, let me know if I can help |
Actually... there may be instances where empty is a valid state (like a null state). |
Empty or undefined? Empty is ok, undefined is evil. |
@DennisOSRM - agreed. It's already initialised to 'invalid_type' so yes to 'empty' at least |
Latest code is now at https://github.com/artemp/variant I've added a Makefile target called
|
I'll add: so I think object size is not looking like an important factor to push on this. But this custom variant is slightly faster (which is remarkable since its not yet heavily optimized) and would allow us to avoid the boost dependency, so it seems worthwhile on those accounts to keep pushing on this. Here are the timing results I'm seeing on a 2.8 GHz i7 mac with
|
Ubuntu precise/g++-4.8 results:
Benchmark:
sizes:
|
More findings. At least with clang++ on OS X I can further shrink the final binary for the minimal test by forcing inlining. Using
|
Now hitting as fast as
|
@artemp I can't access your repo. |
@springmeyer yeah, boost variant didn't give us a big binary size increase; I tested that before switching to it. |
I turned off multi-threaded which distorts the results. I had a look at the performance experiments and I am seeing more of a mixed result. The performance difference comes from constructing the |
Yeah, the multi-threading I added was purely to ensure things didn't crash with threaded load, not intended as meaningful for perf - sorry should not have left that in there. |
I think this is ready to merge. No need to optimize more. I've confirmed that the branch with @artemp's variant works (builds fine, app runs well) and also switching back to diff --git a/include/llmr/style/value.hpp b/include/llmr/style/value.hpp
index 2e9d661..b90f824 100644
--- a/include/llmr/style/value.hpp
+++ b/include/llmr/style/value.hpp
@@ -1,12 +1,12 @@
#ifndef LLMR_STYLE_VALUE
#define LLMR_STYLE_VALUE
-#include <llmr/util/variant.hpp>
+#include <boost/variant.hpp>
#include <llmr/util/pbf.hpp>
namespace llmr {
-typedef ::util::variant<bool, int64_t, uint64_t, double, std::string> Value;
+typedef boost::variant<bool, int64_t, uint64_t, double, std::string> Value;
Value parseValue(pbf data); While ideally we won't ever need to switch back to boost::variant, having this easy to do will offer a fallback if we need to quickly dodge any unforeseen bugs. |
👍 |
As discussed with @kkaefer and @artemp - we should assess writing our own C++ variant implementation:
boost::variant
is our only boost dependency right now, and dropping it would ease setup@artemp has made great progress on a prototype and has started benchmarking. Code is at https://github.com/artemp/variant
Next actions:
binary visitor
, recursive support?)