Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "git://github.com/mapbox/carmen-cache.git",
"type": "git"
},
"version": "0.21.3",
"version": "0.21.3-optimize",
"dependencies": {
"nan": "~2.10.0",
"node-pre-gyp": "~0.10.1"
Expand Down
26 changes: 12 additions & 14 deletions src/coalesce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ void coalesceSingle(uv_work_t* req) {
unsigned long m = grids.size();
double relevMax = 0;
std::vector<Cover> covers;
covers.reserve(m);

uint32_t length = 0;
uint32_t lastId = 0;
Expand Down Expand Up @@ -438,7 +437,6 @@ void coalesceSingle(uv_work_t* req) {
std::size_t added = 0;
std::vector<Context> contexts;
std::size_t max_contexts = 40;
contexts.reserve(max_contexts);
for (auto&& cover : covers) {
// Stop at 40 contexts
if (added == max_contexts) break;
Expand All @@ -453,7 +451,6 @@ void coalesceSingle(uv_work_t* req) {
uint32_t mask = 0;
contexts.emplace_back(std::move(cover), mask, relev);
}

coalesceFinalize(baton, std::move(contexts));
} catch (std::exception const& ex) {
baton->error = ex.what();
Expand All @@ -473,8 +470,10 @@ void coalesceMulti(uv_work_t* req) {
// Cache zoom levels to iterate over as coalesce occurs.
std::vector<intarray> zoomCache;
zoomCache.reserve(stackSize);
double maxrelev = 0;
for (auto const& subq : stack) {
intarray zooms;
zoomCache.emplace_back();
auto& zooms = zoomCache.back();
std::vector<bool> zoomUniq(22, false);
for (auto const& subqB : stack) {
if (subq.idx == subqB.idx) continue;
Expand All @@ -483,7 +482,6 @@ void coalesceMulti(uv_work_t* req) {
zoomUniq[subqB.zoom] = true;
zooms.emplace_back(subqB.zoom);
}
zoomCache.push_back(std::move(zooms));
}

// Coalesce relevs into higher zooms, e.g.
Expand Down Expand Up @@ -570,12 +568,8 @@ void coalesceMulti(uv_work_t* req) {

uint64_t zxy = (z * POW2_28) + (cover.x * POW2_14) + (cover.y);

// Reserve stackSize for the coverList. The vector
// will grow no larger that the size of the input
// subqueries that are being coalesced.
std::vector<Cover> covers;
covers.reserve(stackSize);
covers.push_back(cover);
covers.push_back(std::move(cover));
uint32_t context_mask = cover.mask;
double context_relev = cover.relev;

Expand Down Expand Up @@ -612,7 +606,7 @@ void coalesceMulti(uv_work_t* req) {
}
}
}

maxrelev = std::max(maxrelev, context_relev);
if (last) {
// Slightly penalize contexts that have no stacking
if (covers.size() == 1) {
Expand All @@ -621,7 +615,9 @@ void coalesceMulti(uv_work_t* req) {
} else if (covers[0].mask > covers[1].mask) {
context_relev -= 0.01;
}
contexts.emplace_back(std::move(covers), context_mask, context_relev);
if (maxrelev - context_relev < .25) {
contexts.emplace_back(std::move(covers), context_mask, context_relev);
}
} else if (first || covers.size() > 1) {
cit = coalesced.find(zxy);
if (cit == coalesced.end()) {
Expand All @@ -640,7 +636,9 @@ void coalesceMulti(uv_work_t* req) {
// append coalesced to contexts by moving memory
for (auto&& matched : coalesced) {
for (auto&& context : matched.second) {
contexts.emplace_back(std::move(context));
if (maxrelev - context.relev < .25) {
contexts.emplace_back(std::move(context));
}
}
}

Expand Down Expand Up @@ -720,4 +718,4 @@ void coalesceFinalize(CoalesceBaton* baton, std::vector<Context>&& contexts) {
}
}

} // namespace carmen
} // namespace carmen
6 changes: 6 additions & 0 deletions src/cpp_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ struct Cover {
double distance;
double scoredist;
bool matches_language;

Cover() = default;
Cover(Cover const& c) = default;
Cover& operator=(Cover const& c) = delete;
Cover& operator=(Cover&& c) = default;
Cover(Cover&& c) = default;
};

struct Context {
Expand Down
4 changes: 2 additions & 2 deletions src/rocksdbcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ intarray __getmatching(RocksDBCache const* c, std::string phrase, bool match_pre

if (vals.first != vals.second) {
value_type unadjusted_lastval = *(vals.first);
grids.emplace_back(sortableGrid{
grids.emplace_back(
vals.first,
vals.second,
unadjusted_lastval,
matches_language});
matches_language);
rh.push(matches_language ? unadjusted_lastval | LANGUAGE_MATCH_BOOST : unadjusted_lastval, grids.size() - 1);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/rocksdbcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@ namespace carmen {
#define PREFIX_MAX_GRID_LENGTH 500000

struct sortableGrid {
sortableGrid(protozero::const_varint_iterator<uint64_t> _it,
protozero::const_varint_iterator<uint64_t> _end,
value_type _unadjusted_lastval,
bool _matches_language)
: it(_it),
end(_end),
unadjusted_lastval(_unadjusted_lastval),
matches_language(_matches_language) {
}
protozero::const_varint_iterator<uint64_t> it;
protozero::const_varint_iterator<uint64_t> end;
value_type unadjusted_lastval;
bool matches_language;
sortableGrid() = delete;
sortableGrid(sortableGrid const& c) = delete;
sortableGrid& operator=(sortableGrid const& c) = delete;
sortableGrid& operator=(sortableGrid&& c) = default;
sortableGrid(sortableGrid&& c) = default;
};

struct MergeBaton : carmen::noncopyable {
Expand Down