-
Notifications
You must be signed in to change notification settings - Fork 0
Performance optimizations for RandomStringUtils #2
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
Performance optimizations for RandomStringUtils #2
Conversation
This commit improves the performance of RandomStringUtils: * Reduces the number of random bytes generated and the number of calls to the random number generator, by using a cache system `AmortizedRandomBits`. * Optimizes the case of alphanumerical strings, reducing the number of rejections in the rejection sampling. See comments in code for details.
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## Secure_RandomStringUtils #2 +/- ##
===========================================================
Coverage ? 92.50%
Complexity ? 7773
===========================================================
Files ? 201
Lines ? 15940
Branches ? 2830
===========================================================
Hits ? 14746
Misses ? 652
Partials ? 542 ☔ View full report in Codecov by Sentry. |
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.
Hello @fabrice102 !
Thank you for your contribution.
I'm OK with the PR, but, I'd like to resolve the discussion around the change in behavior this PR addresses first before making changes geared toward performance claims.
I've made some low-level comments.
Also, note the build failures due to checkstyle issues.
In the future, run mvn
by itself to run all build checks before pushing.
TY! 😄
src/main/java/org/apache/commons/lang3/AmortizedRandomBits.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/lang3/AmortizedRandomBits.java
Outdated
Show resolved
Hide resolved
Hi @garydgregory! Thanks for the feedback! I'll submit a new version on Monday. |
* Fix 2 checkstyle errors. * Apply suggestions from review for garydgregory#2 * Improve comments in new (non-public) class `AmortizedRandomBits` to match comments in other classes.
…g() (#1235) * Reimplement RandomStringUtils on top of SecureRandom#getInstanceStrong() The previous implementation used ThreadLocalRandom#current() * Performance optimizations for RandomStringUtils This commit improves the performance of RandomStringUtils: * Reduces the number of random bytes generated and the number of calls to the random number generator, by using a cache system `AmortizedRandomBits`. * Optimizes the case of alphanumerical strings, reducing the number of rejections in the rejection sampling. See comments in code for details. * Code style and comment improvements * Fix 2 checkstyle errors. * Apply suggestions from review for garydgregory#2 * Improve comments in new (non-public) class `AmortizedRandomBits` to match comments in other classes. * Make class final - Rename package-private class - Whitespace - Add null check - Add serialVersionUID - Remove redunant type cast - Throw IllegalStateException, not RuntimeException - nextBytes() should throw NullPointerException per contract - Javadoc: Use longer lines * Apply comments by aherbert in 55a70c8#r143834333 --------- Co-authored-by: Gary Gregory <gardgregory@gmail.com> Co-authored-by: Fabrice Benhamouda <yfabrice@amazon.com>
This commit improves the performance of RandomStringUtils:
AmortizedRandomBits
.See comments in code for details.