Split out JS and pure-C++ components of carmen-cache - #132
Conversation
…n memory and rocks caches via templates
…king the bindings generic
|
\o/ this is great! |
|
This is absolutely fantastic! Going to open the door for so much more work on shared modules! |
| #pragma clang diagnostic ignored "-Wunused-local-typedef" | ||
| #pragma clang diagnostic ignored "-Wunused-parameter" | ||
| #pragma clang diagnostic ignored "-Wpadded" | ||
| #pragma clang diagnostic ignored "-Wold-style-cast" |
There was a problem hiding this comment.
Instead of adding all these pragmas I recommend using -isystem to suppress warnings from headers we don't control like at mapbox/node-cpp-skel#42
There was a problem hiding this comment.
Cool, makes sense. This is just a move of this include from one file to another so I kept it the same, but this is a good tip to apply across the board
There was a problem hiding this comment.
okay, sorry I missed that - okay then, of course, to handle separately and not in this PR
| bool pack(std::string filename); | ||
| std::vector<std::pair<std::string, langfield_type>> list(); | ||
| std::vector<uint64_t> _get(std::string phrase, std::vector<uint64_t> languages); | ||
| std::vector<uint64_t> _getmatching(std::string phrase, bool match_prefixes, std::vector<uint64_t> languages); |
There was a problem hiding this comment.
These arguments should likely be passed as const& to avoid copies.
There was a problem hiding this comment.
Yeah for sure, I need to go through and tweak these. I was also looking maybe at using c++17 string_views instead, at least for the strings, because I think I can instantiate them from Rust strings as well in a zero-copy way, whereas I don't think I can make a c++ string from a non-owned bare char* pointer and length without a copy. Will most likely do const& pointers for the vectors, though (looks like there's an array equivalent to string_view, span, but it's in c++20 rather than 17, so probably a no-go).
Do I need to do similar things for functions that return vectors? It's not clear to me if those are copies, or if they'll be automatically optimized into moves, or if I need to manually return std::move(X) or what.
There was a problem hiding this comment.
Using string_view is a good idea, but no need to use c++17 - you can use protozero::data_view which is a c++11 implementation of string_view.
Do I need to do similar things for functions that return vectors? It's not clear to me if those are copies, or if they'll be automatically optimized into moves, or if I need to manually return std::move(X) or what.
No need to do anything for the return values, the compiler with use RVO without std::move when returning arguments in this case.
Great idea. I recommend using https://github.com/mapbox/hpp-skel as scaffolding for pure C/C++ files since it will give you free setup for pure C++ unit tests, sanitizers, and codecov integration, without the complexity that node.js builds add. Yay, no more gyp.
Is there no way to talk to C++ via rust? If not and you need to wrap in a C API I'm curious how to do this safely. This is not something that I know how to do well, but I did experiment with it once a bunch of years ago: https://github.com/springmeyer/mapnik-c-api |
Only via |
|
👌 @apendleton - thanks for the details. |
…ache objects to tear out the rest of the JS dependency in coalesce, and then move all the JS and uv/thread stuff out of coalesce.* and into binding.*
…dor-prefixed upstream, and then clang-tidy everything
|
Progress for today: I went ahead and split up coalesce. Bigger changes here. I also got clang tidy and clang format to pass. It looks like maybe a new version of clang tidy got introduced into Mason or something, because a bunch of stuff changed, and the config file needed tweaking to continue to behave the same. @aarthykc FYI: clang-tidy decided all on its own to change a couple of the |
…d the other way made tests fail
|
This has been stagnating for awhile and is preventing other carmen-cache work because of concerns about branch divergence, so I'm wrapping this up and pruning things from the scope. The main PR body is up to date, but to be explicit, what's in:
what's not, for now:
These things can all be done non-disruptively later, and won't interfere with unrelated work that needs to happen in carmen-cache. Things I'm doing now:
|
|
At least running locally, this looks like a ~1% performance diff between this branch and master, which might well just be noise. |
|
@springmeyer nobody else on Search besides me felt comfortable reviewing this PR -- if you have a sec, would you mind giving it another glance so we can go ahead and merge it? The two things you had suggested before were the pragma change, which we had decided was out of scope for this PR, and the The main additional changes that have taken place since you last reviewed besides that pass-by-reference stuff:
We also aren't adding stand-alone tests or a non-JS Makefile right now; again, definitely still interested, but mostly just looking to get this merged sooner rather than later so that branch divergence doesn't keep other unrelated streams of work from starting. |
springmeyer
left a comment
There was a problem hiding this comment.
This looks good. I did a quick scan through all the files. Obviously a lot of changes, but everything looks reasonable on first glance. The new use of auto and other refactorings seem 👍
@aarthykc this is the working branch I talked about the other day proposing an alternate way of structuring carmen-cache.
Highlights:
MemoryCacheandRocksDBCacheare not NAN/ObjectWrap classes anymore (so, they're not exposed directly to Javascript), they're just pure C++ classes and their functions take normal C++ arguments and return normal C++ typesRocksDBCache(which used to be a JS type) is nowJSCache<RocksDBCache>and the oldMemoryCacheis nowJSCache<MemoryCache>(also aliased asJSRocksDBCacheandJSMemoryCache, respectively, though maybe I should just be consistent everywhere).The goal is to get to the point where
rocksdbcache.[ch]ppandmemorycache.[ch]ppcan be included into other projects that don't know about Node/NAN at all (and don't pull innan.h) but I'm not there yet.In scope:
merge(EDIT: killed merge), etc., need to dieTODOcomments that need to be dealt with -- at least one of those keeps tests from fully passing at presentPunting for later:
binding.[ch]ppbut this file is starting to get unwieldy again -- probably we need to split it back up again, so, multiple files of JS stuff and multiple files of not-JS stuffextern Cwrapper so non-C++ stuff can get at it, and figure out how to build that, maybe alone or maybe including cargo/rustccc @ingalls @springmeyer in case either of you are interested -- this is a spare-cycles experiment, to be clear