RFR: 8324646: Avoid Class.forName in SecureRandom constructor
Oli Gillespie
ogillespie at openjdk.org
Wed Jan 24 15:31:41 UTC 2024
Avoid expensive `Class.forName` call when constructing Providers such as `SecureRandom` which take constructor parameters. This can easily be cached in EngineDescription (this cache already existed before, it was removed in [JDK-8280970](https://bugs.openjdk.org/browse/JDK-8280970) as unused, I'm bringing it back unchanged to support this new usage).
Benchmark results on my Linux x86 host show around a 20% reduction in time to create a new `SecureRandom` instance. Most of the remaining overhead is due to a failing constructor lookup - see [JDK-8324648](https://bugs.openjdk.org/browse/JDK-8324648).
Before
SecureRandomBench.newSecureRandom avgt 2930 +- 50 ns/op
After
SecureRandomBench.newSecureRandom avgt 15 2400 +- 33 ns/op
I have seen multiple real-world applications which call `new SecureRandom()` on the hot path, so I believe efficiency here is important.
-------------
Commit messages:
- 8324646 - Avoid Class.forName in SecureRandom constructor
Changes: https://git.openjdk.org/jdk/pull/17559/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17559&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8324646
Stats: 30 lines in 2 files changed: 29 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/17559.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/17559/head:pull/17559
PR: https://git.openjdk.org/jdk/pull/17559
More information about the security-dev
mailing list