Skip to content

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Jan 30, 2025

  • relates to Possibly replace ThreadLocalRandom #1749
  • experimental new RandomNumberGenerator API that allows us to plug in different RandomGenerators based on the config (to be done)
  • so far, I'm just plugging in the API to catch compile issues
  • later, I will add the new configs and RandomNumberGenerator.get() will react to the config
  • for performance reasons, the init of RandomNumberGenerator.get() will happen once so the config will be read just once
  • not necessarily going to be merged

@pjfanning pjfanning changed the title [WIP] Thread local random [WIP] New RandomNumberGenerator API Jan 30, 2025
@He-Pin
Copy link
Member

He-Pin commented Feb 11, 2025

Another thing is with the current implementation, the virtual thread is never pooled, which means the ThreadLocalRandom will not leak the thread locals

@pjfanning
Copy link
Member Author

So far, it seems that the performance is lower if you do not use the ThreadLocalRandom. The speed is still good and I don't think we are in a hotspot area where the small perf loss here will make a big diff. I don't think anyone should use this option unless they have a good reason to worry about their virtual thread usage leading to an excessive amount of object instance creation (one ThreadLocalRandom instance per virtual thread).

@pjfanning pjfanning added this to the 2.0.0-M1 milestone Sep 2, 2025
scalafmt

some compile issues

Update ReplicatedShardingTest.java

stub of JEP 356 generator

Update RandomNumberGenerator.scala

java version check

Update RandomNumberGenerator.scala

add test

Update RandomNumberGenerator.scala

add test

Update RandomNumberGeneratorJava21Spec.scala

merge issue

scalafmt
@pjfanning pjfanning modified the milestones: 2.0.0-M1, 2.0.0-M2 Oct 8, 2025
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