Skip to content

Fix more performance issues found by cppcheck#51

Closed
dalgaaf wants to merge 61 commits intoceph:masterfrom
dalgaaf:wip-da-sca-cppcheck-performance-2
Closed

Fix more performance issues found by cppcheck#51
dalgaaf wants to merge 61 commits intoceph:masterfrom
dalgaaf:wip-da-sca-cppcheck-performance-2

Conversation

@dalgaaf
Copy link
Contributor

@dalgaaf dalgaaf commented Feb 13, 2013

Here some more patches to fix performance issues found by cppcheck. This should now cover - together with wip-da-sca-cppcheck-performance - the following issues:

  • use empty() instead of size() to check for emptiness
  • dont't pass string::c_str() to string arguments
  • prevent useless value assignment
  • pass some objects by reference instead of by-value

Fix issues found by cppcheck:

[src/auth/cephx/CephxProtocol.h:469]: (performance) Function
  parameter 'key' should be passed by reference.

Pass CryptoKey by reference as already done in encode_encrypt().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

warning from cppcheck was:
[src/mds/journal.cc:470]: (performance) Possible inefficient
  checking for 'old_inodes' emptiness.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

warning from cppcheck was:
[src/mon/AuthMonitor.cc:210]: (performance) Possible inefficient
  checking for 'pending_auth' emptiness.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Using empty() in this case makes the code more logical.

warning from cppcheck was:

[src/mon/OSDMonitor.h:59]: (performance) Possible inefficient
  checking for 'reporters' emptiness.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

warning from cppcheck was:
[src/mon/Monitor.cc:487]: (performance) Possible inefficient
  checking for 'initial_members' emptiness.
[src/mon/Monitor.cc:1361]: (performance) Possible inefficient
  checking for 'timecheck_skews' emptiness.
[src/mon/Monitor.cc:2302]: (performance) Possible inefficient
  checking for 'timecheck_waiting' emptiness.
[src/mon/Monitor.cc:2547]: (performance) Possible inefficient
  checking for 'timecheck_waiting' emptiness.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

This replaces also some size() >=/== checks.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

This replaces also some size() >=/== checks.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

This replaces also some size() >=/== checks.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix issue found by cppcheck:
[src/osdc/Objecter.cc:989] -> [src/osdc/Objecter.cc:992]: (performance)
  Variable 'check_for_latest_map' is reassigned a value before the old
  one has been used.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

This way the code is more logical.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix issue found by cppcheck:
[src/rgw/rgw_admin.cc:710] -> [src/rgw/rgw_admin.cc:714]:
  (performance) Variable 'ret' is reassigned a value before
  the old one has been used.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix issue found by cppcheck:

[src/rgw/rgw_log.cc:340]: (performance) Passing the result of c_str() to a
  function that takes std::string as argument no. 4 is slow and redundant.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
…iness

Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
…tiness

Use empty() since it should be prefered as it has, following the
standard, a constant time complexity regardless of the containter
type. The same is not guaranteed for size().

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() instead of '!size()' for performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix issue found by cppcheck:
[src/rgw/rgw_rest_swift.cc:770]: (performance) Passing the result of
  c_str() to a function that takes std::string as argument no. 1 is
  slow and redundant.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of 'size()' to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of 'size()' to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Print some more results to fix issue found by cppcheck:

[src/scratchtoolpp.cc:111] -> [src/scratchtoolpp.cc:114]:
  (performance) Variable 'r' is reassigned a value before
  the old one has been used.
[src/scratchtoolpp.cc:207] -> [src/scratchtoolpp.cc:208]:
  (performance) Variable 'r' is reassigned a value before
  the old one has been used.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of 'size() > 0' to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of 'size()' to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of size() to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() instead of '!size()' to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() instead of '!size()' and "size() == 0" to check for emptiness
for performance reasons and since it's more logical.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() instead of size() to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of size() to check for emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use !empty() instead of size() to check for non-emptiness for
performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Use empty() instead of 'size() == 0' or 'size() < 1' to check
for emptiness for performance reasons.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix some smaller performance related issues from cppcheck due to
"Variable '..xy..' is reassigned a value before the old one has been used.

Fix some indention.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
@gregsfortytwo
Copy link
Member

Merged with a few modifications as of ffda2ea. More discussion on the mailing list.

@dalgaaf
Copy link
Contributor Author

dalgaaf commented Feb 14, 2013

@gregsfortytwo: Thanks. AFAICS everything is in except the gtest patch. Correct me if I'm wrong.

XinzeChi pushed a commit to XinzeChi/ceph that referenced this pull request Jan 29, 2016
…-opt

ReplicatedPG:: find_object_context clear extra creation (head,snapdir)
ddiss pushed a commit to ddiss/ceph that referenced this pull request Oct 25, 2016
port civetweb https fix

Reviewed-by: Nathan Cutler <ncutler@suse.com>
ricardoasmarques added a commit to ricardoasmarques/ceph that referenced this pull request Jan 30, 2018
mgr/dashboard_v2: Fix bug in AuthRequired decorator
dotnwat added a commit that referenced this pull request Jul 29, 2018
lixiaoy1 added a commit to lixiaoy1/ceph that referenced this pull request Apr 8, 2020
…o 'wip-librbd-rwl-3'

Resolve "Performance degraded on branch wip-librbd-rwl-3"

Closes ceph#51

See merge request sdpeters/ceph-rwl!33
irq0 pushed a commit to irq0/ceph that referenced this pull request Oct 14, 2022
rgw/sfs: ensure sqlite user ops hold required locks
tobias-urdin pushed a commit to tobias-urdin/ceph that referenced this pull request Aug 2, 2023
Fall back when nuking buckets

Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
athanatos pushed a commit to athanatos/ceph that referenced this pull request Feb 14, 2025
server: delayed tag calculation as a template parameter

Reviewed-by: J. Eric Ivancich <ivancich@redhat.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.

2 participants