ULIDGenerator

wvlet.airframe.ulid.ULID$.ULIDGenerator
class ULIDGenerator(random: () => Array[Byte])

ULID generator.

Value parameters

random

a function that returns a 80-bit random values in Array[Byte] (size:10)

timeSource

a function that returns the current time in milliseconds (e.g. java.lang.System.currentTimeMillis())

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def newULID: ULID
def newULIDFromMillis(unixTimeMillis: Long): String
def newULIDString: String

Generate a new ULID string.

Generate a new ULID string.

Tips for optimizing performance:

  1. Reduce the number of Random number generation. SecureRandom is quite slow, so within the same milliseconds, just incrementing the randomness part will provide better performance. 2. Generate random in Array[Byte] (10 bytes = 80 bits). Regular Random uses 48-bit seed, so calling Random.nextInt (32 bits) x 3 is faster, but SecureRandom has optimization for Array[Byte] generation, which is much faster than calling nextInt three times. 3. ULIDs are often used in the string value form (e.g., transaction IDs, object IDs which can be embedded to URLs, etc.). Generating ULID String from the beginning is ideal. 4. In base32 encoding/decoding, use bit-shift operators as much as possible to utilize CPU registers and memory cache.

Attributes