Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change id generation function #150

Closed
maxakuru opened this issue Apr 16, 2024 · 1 comment
Closed

change id generation function #150

maxakuru opened this issue Apr 16, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@maxakuru
Copy link
Member

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 maxakuru added the bug Something isn't working label Apr 16, 2024
@maxakuru maxakuru self-assigned this Apr 16, 2024
This was referenced Apr 16, 2024
@maxakuru
Copy link
Member Author

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%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant