adobe / helix-rum-js

Helix RUM Event Generator for JavaScript
Apache License 2.0
1 stars 8 forks source link

change id generation function #150

Closed maxakuru closed 5 months ago

maxakuru commented 6 months ago

current implementation has a high rate of empty ids generated (~2%)

we should change it to have similar collision rate (~0.4%), but more evenly spread throughout id values

maxakuru commented 6 months ago

dumping some stats here to compare the two id methods using 1M iterations to simulate ~24 hours of events for a large site

[A]: Array.from({ length: 75 }, (_, i) => String.fromCharCode(48 + i)).filter((a) => /\d|[A-Z]/i.test(a)).filter(() => Math.random() * 75 > 70).join('')

  11825.2205ms duration, 0.0118ms average
  unique results:  604597
  average frequency:  1.6540
  collision rate: 0.3954%

  top 10: 
   => 13730 (2.27%)
  8 => 1065 (0.18%)
  V => 1051 (0.17%)
  1 => 1044 (0.17%)
  h => 1038 (0.17%)
  K => 1038 (0.17%)
  S => 1033 (0.17%)
  i => 1032 (0.17%)
  T => 1029 (0.17%)
  G => 1023 (0.17%)

  bottom 10: 
  2ACMNUqtx => 1 (0.00%)
  01GJQU => 1 (0.00%)
  6CTVYcir => 1 (0.00%)
  BEFKQj => 1 (0.00%)
  016JXg => 1 (0.00%)
  anuw => 1 (0.00%)
  45NRcm => 1 (0.00%)
  8HSrs => 1 (0.00%)
  79ahv => 1 (0.00%)
  MYek => 1 (0.00%)
[B]: Math.random().toString(36).slice(-4)

  556.9435ms duration, 0.0006ms average
  unique results:  728323
  average frequency:  1.3730
  collision rate: 0.2717%

  top 10: 
  72fh => 8 (0.00%)
  84mb => 8 (0.00%)
  kr1l => 7 (0.00%)
  b8ta => 7 (0.00%)
  8vdc => 7 (0.00%)
  4hll => 7 (0.00%)
  eszi => 7 (0.00%)
  s629 => 7 (0.00%)
  oj8n => 7 (0.00%)
  hjyb => 7 (0.00%)

  bottom 10: 
  nb13 => 1 (0.00%)
  smwi => 1 (0.00%)
  4q0f => 1 (0.00%)
  prvx => 1 (0.00%)
  8bis => 1 (0.00%)
  47qb => 1 (0.00%)
  q4nw => 1 (0.00%)
  ilhg => 1 (0.00%)
  m57f => 1 (0.00%)
  t8mv => 1 (0.00%)