Skip to content
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

[CP #1626 > support/v5.12] [core] expmap performance improvement #1630

Merged
merged 1 commit into from
Jun 14, 2024
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
31 changes: 16 additions & 15 deletions ecal/core/src/ecal_expmap.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* 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 @@ -228,27 +228,28 @@ namespace eCAL
// Remove all elements from the cache
void clear()
{
// Assert method is never called when cache is empty
//assert(!_key_tracker.empty());
auto it(_key_tracker.begin());

while (it != _key_tracker.end())
{
_key_to_value.erase(it->second); // erase the element from the map
it = _key_tracker.erase(it); // erase the element from the list
}
};
_key_to_value.clear(); // erase all elements from the map
_key_tracker.clear(); // erase all elements from the list
}

private:

// Maybe pass the iterator instead of the key? or at least only get k once
void update_timestamp(const Key& k)
{
_key_tracker.erase(_key_to_value.at(k).second);
auto new_iterator = _key_tracker.emplace(_key_tracker.end(), std::make_pair(get_curr_time(), k));
_key_to_value.at(k).second = new_iterator;
}
auto it_in_map = _key_to_value.find(k);
if (it_in_map != _key_to_value.end())
{
auto& it_in_list = it_in_map->second.second;

// move the element to the end of the list
_key_tracker.splice(_key_tracker.end(), _key_tracker, it_in_list);

// update the timestamp
it_in_list->first = get_curr_time();
}
}

// Record a fresh key-value pair in the cache
std::pair<typename key_to_value_type::iterator, bool> insert(const Key& k, const T& v)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,11 @@
#include <iostream>
#include <string>
#include <unordered_map>
#include <thread>

int main(int argc, char **argv)
{
int run(0), runs(1000);
int run(0), runs(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

Suggested change
int run(0), runs(10);
int run(0);
int runs(10);

std::chrono::steady_clock::time_point start_time;

// initialize eCAL core API
Expand All @@ -48,8 +49,8 @@ int main(int argc, char **argv)
auto num_topics = topic_info_map.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
std::cout << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));

// GetTopicNames
{
Expand All @@ -66,6 +67,7 @@ int main(int argc, char **argv)
std::cout << "GetTopicsNames : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
std::cout << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}

// finalize eCAL API
Expand Down
Loading