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

feat(autoware_universe_utils): add LRU Cache #8456

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

yhisaki
Copy link
Contributor

@yhisaki yhisaki commented Aug 13, 2024

Description

Implement LRU Cache in autoware_universe_utils. This will allow us to cache the input and output of the function.

We show the performance of Fibonacci, w and w/o lru_cache in example_lru_cache.cpp.

n       With Cache (μs) Without Cache (μs)
-------------------------------------------
30      2               852
31      0               1401
32      0               2212
33      1               3730
34      1               5743
35      1               10082
36      1               14685
37      1               26827
38      1               39542
39      1               70720
40      1               103842

Related links

Parent Issue:

  • Link

How was this PR tested?

Notes for reviewers

None.

Interface changes

None.

Effects on system behavior

None.

Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
@yhisaki yhisaki enabled auto-merge (squash) August 13, 2024 11:59
Copy link

github-actions bot commented Aug 13, 2024

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@github-actions github-actions bot added the component:common Common packages from the autoware-common repository. (auto-assigned) label Aug 13, 2024
@yhisaki yhisaki added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Aug 13, 2024
Copy link
Contributor

@maxime-clem maxime-clem left a comment

Choose a reason for hiding this comment

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

Very nice ! Just today I wanted to use a cache and had to use boost::compute. I will switch to your implementation instead.

@yhisaki yhisaki removed the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Aug 13, 2024
Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
@yhisaki yhisaki added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Aug 13, 2024
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 23.88%. Comparing base (adfd354) to head (6de8284).
Report is 4 commits behind head on main.

Files Patch % Lines
...clude/autoware/universe_utils/system/lru_cache.hpp 53.33% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8456      +/-   ##
==========================================
+ Coverage   23.85%   23.88%   +0.02%     
==========================================
  Files        1379     1381       +2     
  Lines      101614   101672      +58     
  Branches    38644    38675      +31     
==========================================
+ Hits        24238    24282      +44     
- Misses      74918    74928      +10     
- Partials     2458     2462       +4     
Flag Coverage Δ *Carryforward flag
differential 25.83% <53.33%> (?)
total 23.85% <ø> (+<0.01%) ⬆️ Carriedforward from adfd354

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yhisaki yhisaki merged commit ca1d101 into autowarefoundation:main Aug 13, 2024
38 of 39 checks passed
@yhisaki yhisaki deleted the lru_cache branch August 14, 2024 01:57
technolojin pushed a commit to technolojin/autoware.universe that referenced this pull request Aug 15, 2024
technolojin pushed a commit to technolojin/autoware.universe that referenced this pull request Aug 15, 2024
Signed-off-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>
technolojin added a commit to tier4/autoware.universe that referenced this pull request Aug 15, 2024
…performance of map_based_prediction (#1464)

* fix(autoware_map_based_prediction): fix argument order (autowarefoundation#8031)

fix(autoware_map_based_prediction): fix argument order in call `getFrenetPoint()`

Signed-off-by: yucedagonurcan <onur@adastec.com>

Co-authored-by: Shintaro Tomie <58775300+Shin-kyoto@users.noreply.github.com>
Co-authored-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>

* perf(map_based_prediction): remove unncessary withinRoadLanelet() (autowarefoundation#8403)

Signed-off-by: Mamoru Sobue <hilo.soblin@gmail.com>

* perf(map_based_prediction): create a fence LineString layer and use rtree query (autowarefoundation#8406)

use fence layer

Signed-off-by: Mamoru Sobue <hilo.soblin@gmail.com>

* perf(map_based_prediction): apply lerp instead of spline (autowarefoundation#8416)

perf: apply lerp interpolation instead of spline

Signed-off-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>

* perf(autoware_map_based_prediction): improve orientation calculation and resample converted path (autowarefoundation#8427)

* refactor: improve orientation calculation and resample converted path with linear interpolation

Simplify the calculation of the orientation for each pose in the convertPathType function by directly calculating the sine and cosine of half the yaw angle. This improves efficiency and readability. Also, improve the resampling of the converted path by using linear interpolation for better performance.

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>

* Update perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

Co-authored-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>

* Update perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

Co-authored-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>

---------

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
Co-authored-by: Shumpei Wakabayashi <42209144+shmpwk@users.noreply.github.com>
Co-authored-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>

* perf(map_based_prediction): improve world to map transform calculation (autowarefoundation#8413)

* perf(map_based_prediction): improve world to map transform calculation

1. remove unused transforms
2. make transform loading late as possible

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>

* perf(map_based_prediction): get transform only when it is necessary

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>

---------

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>

* feat(autoware_universe_utils): add LRU Cache (autowarefoundation#8456)

Signed-off-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>

* perf(autoware_map_based_prediction): speed up map based prediction by using lru cache in convertPathType (autowarefoundation#8461)

feat(autoware_map_based_prediction): speed up map based prediction by using lru cache in convertPathType

Signed-off-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>

* fix(autoware_map_based_prediction): use surrounding_crosswalks instead of external_surrounding_crosswalks (autowarefoundation#8467)

Signed-off-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>

---------

Signed-off-by: Mamoru Sobue <hilo.soblin@gmail.com>
Signed-off-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>
Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
Signed-off-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>
Co-authored-by: Onur Can Yücedağ <onur@adastec.com>
Co-authored-by: Shintaro Tomie <58775300+Shin-kyoto@users.noreply.github.com>
Co-authored-by: Kotaro Uetake <60615504+ktro2828@users.noreply.github.com>
Co-authored-by: Mamoru Sobue <hilo.soblin@gmail.com>
Co-authored-by: Shumpei Wakabayashi <42209144+shmpwk@users.noreply.github.com>
Co-authored-by: Yukinari Hisaki <42021302+yhisaki@users.noreply.github.com>
xtk8532704 pushed a commit to tier4/autoware.universe that referenced this pull request Aug 15, 2024
Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
Signed-off-by: xtk8532704 <1041084556@qq.com>
@dkoldaev
Copy link
Contributor

@yhisaki I just saw this PR, it is a pretty useful tool! Nice performance improvement in the map based prediction node (this is how I found this PR)
Just wanted to point your attention to the testing side. You tested the performance improvements and this is great, but what about some edge cases? I think the main would be to make sure that the cache does not overflow. Say, make cache of size 20 and try to put 25 elements. (P.S. I wrote this also because I remember you passion about testing 😄 )

@yhisaki
Copy link
Contributor Author

yhisaki commented Oct 31, 2024

Thank you for looking at the PR!
Indeed, the edge case testing is insufficient. I'll prepare a PR to enhance the tests as soon as possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:common Common packages from the autoware-common repository. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants