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

Nacho/minor fixes tf2 cache #658

Merged
merged 7 commits into from
Mar 22, 2024

Conversation

nachovizzo
Copy link
Contributor

Follow up on #636

This PR does not introduce any real change, it's just a selective refactor on some parts of the tf2 cache I did back then. It's mainly replacing raw loops with algorithms that one can read and understand what's the code trying to do faster

This also means I didn't embark on a refactoring journey of the entire system. It's just affecting the line of code I was evaluating last year, but I didn't want to avoid contributing to this.

Of course, it would be ideal to refactor more "globally" let's call it but won't have time anytime soon to do this, I'm happy to follow up more reviewing of the implementation in future PRs but for now this is what I can do :)

I tried to be very verbose on a committed level just to make the reviewing process easier

```cpp
TimePoint TimeCache::getLatestTimestamp()
{
  return storage_.front().stamp_;
}
```

And std::list<T>::front() is(gcclib):
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```
```cpp

TimePoint TimeCache::getLatestTimestamp()
{
  // empty list case
  // ...
  return storage_.front().stamp_;
}
```

and std::list<T>::front():
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```
By now reading to this block I can tell that we are preventing to
inserting a new element in the list, that has a timestamp that is
actually older than the max_storage_time_ we allow for
The intent of the code is now more clear, instead of relying on raw
loops, we "find if" there is any element in the list that has a stamp
older than the incoming one. With this we find the position in the list
where we should insert the current timestamp: `storage_it`
Remove if any element is older thant the max_storage_time_ allowed,
relative to the latest(sooner) time seems clear npw
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@fujitatomoya
Copy link

@ahcorde is this ready to merge? can you confirm?

@ahcorde ahcorde merged commit 8752526 into ros2:rolling Mar 22, 2024
1 of 2 checks passed
ahcorde pushed a commit that referenced this pull request May 29, 2024
* Remove unused parameter

* Make use of API function to improve redability

```cpp
TimePoint TimeCache::getLatestTimestamp()
{
  return storage_.front().stamp_;
}
```

And std::list<T>::front() is(gcclib):
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Same argument as 321bd22

```cpp

TimePoint TimeCache::getLatestTimestamp()
{
  // empty list case
  // ...
  return storage_.front().stamp_;
}
```

and std::list<T>::front():
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Improve readbility by relying on STL functions

By now reading to this block I can tell that we are preventing to
inserting a new element in the list, that has a timestamp that is
actually older than the max_storage_time_ we allow for

* Remove hardcoded algorithmg for STL one

The intent of the code is now more clear, instead of relying on raw
loops, we "find if" there is any element in the list that has a stamp
older than the incoming one. With this we find the position in the list
where we should insert the current timestamp: `storage_it`

* Remove to better express what this pointer is represetngin

* Replace raw loop for STL algorithm

Remove if any element is older thant the max_storage_time_ allowed,
relative to the latest(sooner) time seems clear npw
ahcorde pushed a commit that referenced this pull request May 29, 2024
* Remove unused parameter

* Make use of API function to improve redability

```cpp
TimePoint TimeCache::getLatestTimestamp()
{
  return storage_.front().stamp_;
}
```

And std::list<T>::front() is(gcclib):
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Same argument as 321bd22

```cpp

TimePoint TimeCache::getLatestTimestamp()
{
  // empty list case
  // ...
  return storage_.front().stamp_;
}
```

and std::list<T>::front():
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Improve readbility by relying on STL functions

By now reading to this block I can tell that we are preventing to
inserting a new element in the list, that has a timestamp that is
actually older than the max_storage_time_ we allow for

* Remove hardcoded algorithmg for STL one

The intent of the code is now more clear, instead of relying on raw
loops, we "find if" there is any element in the list that has a stamp
older than the incoming one. With this we find the position in the list
where we should insert the current timestamp: `storage_it`

* Remove to better express what this pointer is represetngin

* Replace raw loop for STL algorithm

Remove if any element is older thant the max_storage_time_ allowed,
relative to the latest(sooner) time seems clear npw
ahcorde added a commit that referenced this pull request May 29, 2024
…kport #680) (#694)

* Nacho/minor fixes tf2 cache (#658)

* Remove unused parameter

* Make use of API function to improve redability

```cpp
TimePoint TimeCache::getLatestTimestamp()
{
  return storage_.front().stamp_;
}
```

And std::list<T>::front() is(gcclib):
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Same argument as 321bd22

```cpp

TimePoint TimeCache::getLatestTimestamp()
{
  // empty list case
  // ...
  return storage_.front().stamp_;
}
```

and std::list<T>::front():
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Improve readbility by relying on STL functions

By now reading to this block I can tell that we are preventing to
inserting a new element in the list, that has a timestamp that is
actually older than the max_storage_time_ we allow for

* Remove hardcoded algorithmg for STL one

The intent of the code is now more clear, instead of relying on raw
loops, we "find if" there is any element in the list that has a stamp
older than the incoming one. With this we find the position in the list
where we should insert the current timestamp: `storage_it`

* Remove to better express what this pointer is represetngin

* Replace raw loop for STL algorithm

Remove if any element is older thant the max_storage_time_ allowed,
relative to the latest(sooner) time seems clear npw

* [TimeCache] Improve performance for insertData() and pruneList() (#680)

Signed-off-by: Eric Cousineau <eric.cousineau@tri.global>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>

* Don't break ABI

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>

---------

Signed-off-by: Eric Cousineau <eric.cousineau@tri.global>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Ignacio Vizzo <ignacio@dexory.com>
Co-authored-by: Eric Cousineau <eric.cousineau@tri.global>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
ahcorde added a commit that referenced this pull request May 29, 2024
…kport #680) (#693)

* Nacho/minor fixes tf2 cache (#658)

* Remove unused parameter

* Make use of API function to improve redability

```cpp
TimePoint TimeCache::getLatestTimestamp()
{
  return storage_.front().stamp_;
}
```

And std::list<T>::front() is(gcclib):
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Same argument as 321bd22

```cpp

TimePoint TimeCache::getLatestTimestamp()
{
  // empty list case
  // ...
  return storage_.front().stamp_;
}
```

and std::list<T>::front():
```cpp
reference
front() _GLIBCXX_NOEXCEPT
{ return *begin(); }
```

* Improve readbility by relying on STL functions

By now reading to this block I can tell that we are preventing to
inserting a new element in the list, that has a timestamp that is
actually older than the max_storage_time_ we allow for

* Remove hardcoded algorithmg for STL one

The intent of the code is now more clear, instead of relying on raw
loops, we "find if" there is any element in the list that has a stamp
older than the incoming one. With this we find the position in the list
where we should insert the current timestamp: `storage_it`

* Remove to better express what this pointer is represetngin

* Replace raw loop for STL algorithm

Remove if any element is older thant the max_storage_time_ allowed,
relative to the latest(sooner) time seems clear npw

* [TimeCache] Improve performance for insertData() and pruneList() (#680)

Signed-off-by: Eric Cousineau <eric.cousineau@tri.global>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>

* Don't break ABI

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>

---------

Signed-off-by: Eric Cousineau <eric.cousineau@tri.global>
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Ignacio Vizzo <ignacio@dexory.com>
Co-authored-by: Eric Cousineau <eric.cousineau@tri.global>
Co-authored-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants