-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Refactor: Fix compiler warning in prevector.h #14651
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
Conversation
|
Please send the leveldb changes upstream. |
leveldb changes sent upstream. Rebased to only include the non-leveldb patch. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
@ldm5180 Can you post the warnings emitted? What gcc version are you using? |
|
What are the performance impacts of this change? |
gcc version 8.2.0 (Ubuntu 8.2.0-7ubuntu1) |
Expect, no impact. Is there a performance analysis test suite? There are a few different cases. Here are them shown in the Compiler Explorer:
In both functions, when a trivial type is used there is no difference or the In both functions, when a nontrivial type is used, it gets better optimized with the |
|
Concept ACK; from what I read is that for character types |
kallewoof
left a comment
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.
utACK aa6f3d7db443c1154eda78f6fb006a69aa20ce3a
Problem: - IS_TRIVIALLY_CONSTRUCTIBLE macro does not work correctly resulting in `memset()` usage to set a non-trivial type to 0 when `nontrivial_t` is passed in from the tests. - Warning reported by GCC when compiling with `--enable-werror`. Solution: - Use the standard algorithm `std::fill_n()` and let the compiler determine the optimal way of looping or using `memset()`.
Yes, there is |
|
I think the important benchmarks are the The differences between g++ and clang++ are pretty stark, but the numbers within each version are very similar. Running them several times shows that they are not super stable number (at least on my machine). I don't know what your target is for acceptable, but here are some results: For clang, these might be outside the margin of error. For gcc, I don't think it is. Baseline GCC: New version GCC: Baseline Clang: New version Clang: |
|
utACK 76e13b5, nice code simplification and tiny performance bonus (with clang). |
76e13b5 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) Pull request description: Fixing warnings reported by GCC: memset of non-trivial type Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
69ca487 Implement prevector::fill once (Ben Woosley) 7bad78c Drop defunct IS_TRIVIALLY_CONSTRUCTIBLE handling from prevector.h (Ben Woosley) Pull request description: This is clean-up post #14651: * Use one implementation of `prevector::fill`, as it's possible now that the implementations are identical. * Only apply the `IS_TRIVIALLY_CONSTRUCTIBLE` handling to the bench file where it is used, and drop the now-unnecessary associated compat includes. Tree-SHA512: 5930b3a17fccd39af10add40202ad97a297aebecc049af72ca920d0d55b3e4c3c30ce864c8a683355895f0196396d4ea56ba9f9637bdc7d16964cdf66c195485
d856989 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) 4cb188e Drop defunct IS_TRIVIALLY_CONSTRUCTIBLE handling from prevector.h (Ben Woosley) c412d5f Reduce redundant code of prevector and speed it up (random-zebra) e6741d0 Add new prevector benchmarks. (random-zebra) Pull request description: Backports from Bitcoin a series of optimizations for `prevector` operations, especially around resizing, which takes a significative portion of the time spent by of `ReadBlockFromDisk()`. Running the benchmark tool before the patch: ``` #Benchmark, count, min, max, avg, minc, maxc, avgc ----------- ------ ---- ---- ---- ----- ----- ---- PrevectorClearTrivial, 3328, 312631, 329431, 320311, 812854, 856536, 832823 PrevectorDestructorTrivial, 3328, 317011, 353344, 325141, 824243, 918711, 845382 PrevectorResizeTrivial, 3328, 321333, 327672, 324713, 835482, 851963, 844269 ``` and after: ``` #Benchmark, count, min, max, avg, minc, maxc, avgc ----------- ------ ---- ---- ---- ----- ----- ---- PrevectorClearTrivial, 65536, 15726, 16368, 16067, 40889, 42559, 41775 PrevectorDestructorTrivial, 65536, 15865, 16416, 16141, 41249, 42684, 41968 PrevectorResizeTrivial, 65536, 16036, 16320, 16213, 41696, 42433, 42156 ``` shows that `prevector::clear()`, `prevector::~prevector()`, and `prevector::resize()` become (on avg) **20X** faster. Based on: - bitcoin#12549 - bitcoin#14651 - bitcoin#14715 ACKs for top commit: Fuzzbawls: utACK d856989 furszy: Quite cool. utACK d856989 Tree-SHA512: 8060458bfd5373448d83a3d905fbc95379cfc1c1aed19b750c98b06a1a6a4ba85a6715865388752a5bd579676e2b2e26d3584ec5b26d51e9ba1380bc4fa73f33
76e13b5 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) Pull request description: Fixing warnings reported by GCC: memset of non-trivial type Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
76e13b5 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) Pull request description: Fixing warnings reported by GCC: memset of non-trivial type Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
76e13b5 warnings: Compiler warning on memset usage for non-trivial type (Lenny Maiorani) Pull request description: Fixing warnings reported by GCC: memset of non-trivial type Tree-SHA512: 357aeac60acfb922851daaf0bd8d4b81e377da7c9b31c2942b54cfdd4129dae61e577fc0a6aa430348cb07abd16ae32f986a64dbb2c1d90ec148f53e7451a229
Fixing warnings reported by GCC: memset of non-trivial type