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
osd: Making use of find to reduce computational complexity #19732
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed quickly but only that one case looked like it would benefit from a change.
src/osd/PrimaryLogPG.cc
Outdated
@@ -424,7 +424,7 @@ void PrimaryLogPG::on_local_recover( | |||
bool got = obc->get_recovery_read(); | |||
assert(got); | |||
|
|||
assert(recovering.count(obc->obs.oi.soid)); | |||
assert(recovering.find(obc->obs.oi.soid) != recovering.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes aren't helpful/useful.. the complexity is the same and they are more verbose.
The point is get rid of patterns like:
if (foo.count(bar) && foo[bar] == baz) {
where a count() precedes an operator[] call. That is two lookups but can be reduced to 1 by using an iterator and comparing to end().
src/osd/PrimaryLogPG.cc
Outdated
@@ -755,7 +761,7 @@ void PrimaryLogPG::maybe_force_recovery() | |||
++it) { | |||
if (*it == get_primary()) continue; | |||
pg_shard_t peer = *it; | |||
if (peer_missing.count(peer) && | |||
if (peer_missing.find(peer) != peer_missing.end() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like here:
auto it = peer_missing.find(peer); if (it != peer_missing.end() && !it->second.get_rmissing.empty()) { ...
Signed-off-by: Shinobu Kinjo <shinobu@redhat.com>
1fbe699
to
79c0e75
Compare
@liewegas Please check when you get a chance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
Signed-off-by: Shinobu Kinjo shinobu@redhat.com