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

tidy: enable performance checks #2505

Merged
merged 1 commit into from
Nov 28, 2023
Merged

tidy: enable performance checks #2505

merged 1 commit into from
Nov 28, 2023

Conversation

Riolku
Copy link
Contributor

@Riolku Riolku commented Nov 27, 2023

With the exception of performance-no-int-to-ptr, this change enables clang tidy's performance-based lints.

The changes made are as follows, in no particular order.

  • Avoid std::endl. std::endl is confusing because it also flushes the buffer, which is often undesirable. Instead, we should just use a newline character.
  • When possible, declare variables as const T& instead of T, since it avoids a copy.
  • When possible, use std::move to avoid a copy. However, if the type is trivially copyable, std::move does nothing and hence should be removed. Furthermore, if the variable to be moved is constant, std::move simply copies, and so std::move is confusing and should be removed. Finally, if the variable is moved, but the function parameter type is const T&, then a move is unnecessary, and again, it should be removed.
  • When using push_back in a loop, we should reserve up front for better performance.
  • When concatenating strings, either we should std::move() the strings, or use string::append. Otherwise, we pay the price of creating temporary strings, instead of just pushing to a single string.
  • Trivial destructors should be declared with = default to allow more aggressive compiler optimizations.

With the exception of performance-no-int-to-ptr, this change enables
clang tidy's performance-based lints.

The changes made are as follows, in no particular order.

- Avoid std::endl. std::endl is confusing because it also flushes the
  buffer, which is often undesirable. Instead, we should just use a newline
  character.
- When possible, declare variables as `const T&` instead of `T`, since
  it avoids a copy.
- When possible, use `std::move` to avoid a copy. However, if the type
  is trivially copyable, `std::move` does nothing and hence should be
  removed. Furthermore, if the variable to be moved is constant,
  `std::move` simply copies, and so `std::move` is confusing and should
  be removed. Finally, if the variable is moved, but the function
  parameter type is `const T&`, then a move is unnecessary, and again,
  it should be removed.
- When using `push_back` in a loop, we should reserve up front for
  better performance.
- When concatenating strings, either we should `std::move()` the
  strings, or use `string::append`. Otherwise, we pay the price of
  creating temporary strings, instead of just pushing to a single
  string.
- Trivial destructors should be declared with `= default` to allow more
  aggressive compiler optimizations.
Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (e216c0c) 91.56% compared to head (fc7c404) 91.57%.

Files Patch % Lines
...operator/persistent/reader/parquet/column_reader.h 50.00% 1 Missing ⚠️
src/processor/operator/order_by/top_k.cpp 0.00% 1 Missing ⚠️
src/processor/result/flat_tuple.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2505   +/-   ##
=======================================
  Coverage   91.56%   91.57%           
=======================================
  Files        1026     1026           
  Lines       37909    37945   +36     
=======================================
+ Hits        34712    34747   +35     
- Misses       3197     3198    +1     

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

@Riolku Riolku merged commit 5e3da89 into master Nov 28, 2023
13 checks passed
@Riolku Riolku deleted the tidy-performance branch November 28, 2023 02:37
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