Skip to content

Commit d95c97e

Browse files
Decrease allocations in QuadTreeIndex
Added a `fields` parameter to GetIndexData method. Change GetIndexData method to skip string fields which are not needed. Relates-To: DATASDK-64 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent 49ef5d4 commit d95c97e

File tree

7 files changed

+147
-103
lines changed

7 files changed

+147
-103
lines changed

olp-cpp-sdk-dataservice-read/src/BlobDataReader.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 HERE Europe B.V.
2+
* Copyright (C) 2020-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,16 +41,25 @@ class BlobDataReader {
4141
return true;
4242
}
4343

44-
size_t GetOffset() { return read_offset_; }
45-
void SetOffset(size_t offset) { read_offset_ = offset; }
44+
template <class T>
45+
bool Skip() {
46+
if (read_offset_ + sizeof(T) > data_.size()) {
47+
return false;
48+
}
49+
read_offset_ += sizeof(T);
50+
return true;
51+
}
52+
53+
size_t GetOffset() const { return read_offset_; }
54+
void SetOffset(const size_t offset) { read_offset_ = offset; }
4655

4756
private:
4857
size_t read_offset_ = 0;
4958
const std::vector<unsigned char>& data_;
5059
};
5160

5261
template <>
53-
bool BlobDataReader::Read<std::string>(std::string& value) {
62+
inline bool BlobDataReader::Read<std::string>(std::string& value) {
5463
size_t end = std::numeric_limits<size_t>::max();
5564
for (size_t i = read_offset_; i < data_.size(); ++i) {
5665
if (data_[i] == 0) {
@@ -69,6 +78,23 @@ bool BlobDataReader::Read<std::string>(std::string& value) {
6978
return true;
7079
}
7180

81+
template <>
82+
inline bool BlobDataReader::Skip<std::string>() {
83+
size_t end = std::numeric_limits<size_t>::max();
84+
for (size_t i = read_offset_; i < data_.size(); ++i) {
85+
if (data_[i] == 0) {
86+
end = i;
87+
break;
88+
}
89+
}
90+
if (end == std::numeric_limits<size_t>::max()) {
91+
return false;
92+
}
93+
94+
read_offset_ = end + 1;
95+
return true;
96+
}
97+
7298
} // namespace read
7399
} // namespace dataservice
74100
} // namespace olp

olp-cpp-sdk-dataservice-read/src/BlobDataWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 HERE Europe B.V.
2+
* Copyright (C) 2020-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ class BlobDataWriter {
4949
};
5050

5151
template <>
52-
bool BlobDataWriter::Write<std::string>(const std::string& value) {
52+
inline bool BlobDataWriter::Write<std::string>(const std::string& value) {
5353
if (write_offset_ + value.size() + 1 > data_.size()) {
5454
return false;
5555
}

olp-cpp-sdk-dataservice-read/src/ReleaseDependencyResolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 HERE Europe B.V.
2+
* Copyright (C) 2020-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ ReleaseDependencyResolver::CheckProtectedTilesInQuad(
111111
// check if quad tree has other protected keys, if not, add quad key to
112112
// release from protected list, othervise add all protected keys left
113113
// for this quad to map
114-
auto index_data = cached_tree.GetIndexData();
114+
auto index_data = cached_tree.GetIndexData(QuadTreeIndex::DataHandle);
115115
TilesDataKeysType protected_keys;
116116
for (const auto& ind : index_data) {
117117
const auto tile_data_key = cache::KeyGenerator::CreateDataHandleKey(

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -743,7 +743,7 @@ client::ApiNoResponse VersionedLayerClientImpl::DeleteFromCache(
743743
return result;
744744
}
745745

746-
auto index_data = cached_tree.GetIndexData();
746+
auto index_data = cached_tree.GetIndexData(QuadTreeIndex::DataHandle);
747747
for (const auto& ind : index_data) {
748748
if (ind.tile_key != tile &&
749749
data_cache_repository.IsCached(layer_id_, ind.data_handle)) {

olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ constexpr std::int32_t kMaxQuadTreeIndexDepth = 4;
4848

4949
SubQuadsResult FlattenTree(const QuadTreeIndex& tree) {
5050
SubQuadsResult result;
51-
auto index_data = tree.GetIndexData();
51+
auto index_data = tree.GetIndexData(QuadTreeIndex::DataHandle);
5252
for (auto& data : index_data) {
5353
const auto it = result.lower_bound(data.tile_key);
5454
if (it == result.end() || result.key_comp()(data.tile_key, it->first)) {
@@ -455,11 +455,12 @@ PrefetchTilesRepository::DownloadVersionedQuadTree(
455455
default_additional_fields, billing_tag_, context);
456456

457457
if (quad_tree.GetStatus() != olp::http::HttpStatusCode::OK) {
458-
OLP_SDK_LOG_WARNING_F(kLogTag,
459-
"GetSubQuads failed(%s, %" PRId64 ", %" PRId32
460-
"), status_code='%d'",
461-
tile_key.c_str(), version, depth, quad_tree.GetStatus());
462-
return {client::ApiError(quad_tree.GetStatus(), quad_tree.GetResponseAsString()),
458+
OLP_SDK_LOG_WARNING_F(
459+
kLogTag,
460+
"GetSubQuads failed(%s, %" PRId64 ", %" PRId32 "), status_code='%d'",
461+
tile_key.c_str(), version, depth, quad_tree.GetStatus());
462+
return {client::ApiError(quad_tree.GetStatus(),
463+
quad_tree.GetResponseAsString()),
463464
quad_tree.GetNetworkStatistics()};
464465
}
465466

0 commit comments

Comments
 (0)