Skip to content

Decrease allocations in QuadTreeIndex #1602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
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
34 changes: 30 additions & 4 deletions olp-cpp-sdk-dataservice-read/src/BlobDataReader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 HERE Europe B.V.
* Copyright (C) 2020-2025 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,16 +41,25 @@
return true;
}

size_t GetOffset() { return read_offset_; }
void SetOffset(size_t offset) { read_offset_ = offset; }
template <class T>
bool Skip() {
if (read_offset_ + sizeof(T) > data_.size()) {
return false;
}
read_offset_ += sizeof(T);
return true;
}

size_t GetOffset() const { return read_offset_; }
void SetOffset(const size_t offset) { read_offset_ = offset; }

private:
size_t read_offset_ = 0;
const std::vector<unsigned char>& data_;
};

template <>
bool BlobDataReader::Read<std::string>(std::string& value) {
inline bool BlobDataReader::Read<std::string>(std::string& value) {
size_t end = std::numeric_limits<size_t>::max();
for (size_t i = read_offset_; i < data_.size(); ++i) {
if (data_[i] == 0) {
Expand All @@ -69,6 +78,23 @@
return true;
}

template <>
inline bool BlobDataReader::Skip<std::string>() {
size_t end = std::numeric_limits<size_t>::max();
for (size_t i = read_offset_; i < data_.size(); ++i) {
if (data_[i] == 0) {
end = i;
break;
}
}
if (end == std::numeric_limits<size_t>::max()) {
return false;

Check warning on line 91 in olp-cpp-sdk-dataservice-read/src/BlobDataReader.h

View check run for this annotation

Codecov / codecov/patch

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

Added line #L91 was not covered by tests
}

read_offset_ = end + 1;
return true;
}

} // namespace read
} // namespace dataservice
} // namespace olp
4 changes: 2 additions & 2 deletions olp-cpp-sdk-dataservice-read/src/BlobDataWriter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 HERE Europe B.V.
* Copyright (C) 2020-2025 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,7 +49,7 @@ class BlobDataWriter {
};

template <>
bool BlobDataWriter::Write<std::string>(const std::string& value) {
inline bool BlobDataWriter::Write<std::string>(const std::string& value) {
if (write_offset_ + value.size() + 1 > data_.size()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 HERE Europe B.V.
* Copyright (C) 2020-2025 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -111,7 +111,7 @@ ReleaseDependencyResolver::CheckProtectedTilesInQuad(
// check if quad tree has other protected keys, if not, add quad key to
// release from protected list, othervise add all protected keys left
// for this quad to map
auto index_data = cached_tree.GetIndexData();
auto index_data = cached_tree.GetIndexData(QuadTreeIndex::DataHandle);
TilesDataKeysType protected_keys;
for (const auto& ind : index_data) {
const auto tile_data_key = cache::KeyGenerator::CreateDataHandleKey(
Expand Down
4 changes: 2 additions & 2 deletions olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2025 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -743,7 +743,7 @@ client::ApiNoResponse VersionedLayerClientImpl::DeleteFromCache(
return result;
}

auto index_data = cached_tree.GetIndexData();
auto index_data = cached_tree.GetIndexData(QuadTreeIndex::DataHandle);
for (const auto& ind : index_data) {
if (ind.tile_key != tile &&
data_cache_repository.IsCached(layer_id_, ind.data_handle)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2025 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@

SubQuadsResult FlattenTree(const QuadTreeIndex& tree) {
SubQuadsResult result;
auto index_data = tree.GetIndexData();
auto index_data = tree.GetIndexData(QuadTreeIndex::DataHandle);
for (auto& data : index_data) {
const auto it = result.lower_bound(data.tile_key);
if (it == result.end() || result.key_comp()(data.tile_key, it->first)) {
Expand Down Expand Up @@ -455,11 +455,12 @@
default_additional_fields, billing_tag_, context);

if (quad_tree.GetStatus() != olp::http::HttpStatusCode::OK) {
OLP_SDK_LOG_WARNING_F(kLogTag,
"GetSubQuads failed(%s, %" PRId64 ", %" PRId32
"), status_code='%d'",
tile_key.c_str(), version, depth, quad_tree.GetStatus());
return {client::ApiError(quad_tree.GetStatus(), quad_tree.GetResponseAsString()),
OLP_SDK_LOG_WARNING_F(

Check warning on line 458 in olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.cpp

View check run for this annotation

Codecov / codecov/patch

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

Added line #L458 was not covered by tests
kLogTag,
"GetSubQuads failed(%s, %" PRId64 ", %" PRId32 "), status_code='%d'",
tile_key.c_str(), version, depth, quad_tree.GetStatus());
return {client::ApiError(quad_tree.GetStatus(),
quad_tree.GetResponseAsString()),

Check warning on line 463 in olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.cpp

View check run for this annotation

Codecov / codecov/patch

olp-cpp-sdk-dataservice-read/src/repositories/PrefetchTilesRepository.cpp#L462-L463

Added lines #L462 - L463 were not covered by tests
quad_tree.GetNetworkStatistics()};
}

Expand Down
Loading
Loading