Skip to content

Use ThreadLocal caching for ExtendedRandom PRNG contexts - #1255

Merged
jasonkatonica merged 1 commit into
IBM:mainfrom
taoliult:main_securerandom_native_2
Jun 3, 2026
Merged

jasonkatonica merged 1 commit into
IBM:mainfrom
taoliult:main_securerandom_native_2

Conversation

@taoliult

@taoliult taoliult commented Mar 9, 2026

Copy link
Copy Markdown
Collaborator

Add ThreadLocal caching for native PRNG contexts used by ExtendedRandom. Each thread creates and reuses a PRNG context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances are created frequently.

Benefits:

  • Reduce native allocation overhead
  • Reuse PRNG contexts per thread
  • Improve performance in RNG-heavy workloads

Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/test/java/ibm/jceplus/jmh/RandomNewInstanceBenchmark.java Outdated
@taoliult
taoliult force-pushed the main_securerandom_native_2 branch 2 times, most recently from 75c4eb8 to 71f77f3 Compare March 11, 2026 21:24
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
@taoliult
taoliult force-pushed the main_securerandom_native_2 branch 2 times, most recently from 4a97876 to fb77737 Compare April 1, 2026 15:18
@taoliult
taoliult force-pushed the main_securerandom_native_2 branch 2 times, most recently from c8e276f to ff9268f Compare April 20, 2026 18:30
Comment thread src/test/java/ibm/jceplus/jmh/RandomNewInstanceBenchmark.java
@taoliult

Copy link
Copy Markdown
Collaborator Author

@johnpeck-us-ibm Sorry, I accidentally clicked the refresh button. I noticed that you had already approved this PR, but I’m not sure if you need to click Approve button again because of that.

@taoliult
taoliult force-pushed the main_securerandom_native_2 branch from 4d16a3f to fe5383a Compare April 28, 2026 16:17
@taoliult
taoliult requested a review from JinhangZhang April 28, 2026 16:18
@taoliult
taoliult force-pushed the main_securerandom_native_2 branch from fe5383a to df3eb8c Compare May 14, 2026 17:59
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated
Comment thread src/main/java/com/ibm/crypto/plus/provider/base/ExtendedRandom.java Outdated

@jasonkatonica jasonkatonica left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add ThreadLocal caching for native PRNG contexts used by
ExtendedRandom. Each thread creates and reuses a PRNG
context for supported DRBG algorithms.

This avoids repeated EXTRAND_create calls when instances
are created frequently.

Benefits:
- Reduce native allocation overhead
- Reuse PRNG contexts per thread
- Improve performance in RNG-heavy workloads

Signed-off-by: Tao Liu <tao.liu@ibm.com>
@taoliult
taoliult force-pushed the main_securerandom_native_2 branch from c05f971 to 1de96ad Compare May 21, 2026 15:20
@taoliult
taoliult requested a review from KostasTsiounis May 21, 2026 15:28

@KostasTsiounis KostasTsiounis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JinhangZhang JinhangZhang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

5 participants