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

Avoid wasted lookup in insert_or_assign method #11

Open
mohitmv opened this issue Mar 23, 2021 · 0 comments
Open

Avoid wasted lookup in insert_or_assign method #11

mohitmv opened this issue Mar 23, 2021 · 0 comments
Labels
optimization Performance Optmization

Comments

@mohitmv
Copy link
Owner

mohitmv commented Mar 23, 2021

Comment from reddit

Implementation of at would be more efficient if you got rid of the first call to contains_key and simply used find directly. You call contains_key to check if something is in the map (doing a map lookup in the process) then, if so, immediately call at on the underlying map (doing a redundant map lookup) to access the value.

insert_or_assign, move, and move_only all have the same problem. move_and_erase is even worse - you either call at on yourself or operator[] on the underlying map, so you do a wasted lookup in BOTH branches.

https://www.reddit.com/r/cpp/comments/m9uwaq/releasing_lazy_map_c_library/grpmxlp?utm_source=share&utm_medium=web2x&context=3

@mohitmv mohitmv added the optimization Performance Optmization label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Performance Optmization
Projects
None yet
Development

No branches or pull requests

1 participant