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

Crystal version #1

Closed
krthr opened this issue Feb 29, 2020 · 9 comments
Closed

Crystal version #1

krthr opened this issue Feb 29, 2020 · 9 comments

Comments

@krthr
Copy link

krthr commented Feb 29, 2020

I have written the Crystal version of this lib: https://github.com/krthr/uuix

@lukeed
Copy link
Owner

lukeed commented Feb 29, 2020

Cool!! I was likely gunna do one in Rust, but dunno how well others already perform.

@krthr
Copy link
Author

krthr commented Feb 29, 2020

The benchmark for Crystal is pretty amazing:

Crystal 0.33.0 [612825a53] (2020-02-14)

LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu
        UUIX: 920.14k (  1.09µs) (± 9.68%)  880B/op        fastest
Crystal UUID: 647.32k (  1.54µs) (± 7.53%)  0.0B/op   1.42× slower

Awesome!

@lukeed
Copy link
Owner

lukeed commented Feb 29, 2020

I saw that – very exciting :D

@krthr
Copy link
Author

krthr commented Mar 1, 2020

Thanks to @skuznetsov, some optimizations have been made. We have achieved quite good results.

bash-3.2$ ./benchmark
Crystal 0.33.0 (2020-02-14)

LLVM: 9.0.1
Default target: x86_64-apple-macosx
        UUIX:   4.67M (213.98ns) (± 3.00%)  113B/op        fastest
Crystal UUID: 783.57k (  1.28µs) (± 2.15%)  0.0B/op   5.96× slower

It would be great to see implementations in other languages.

@lukeed
Copy link
Owner

lukeed commented Mar 1, 2020

haha wow! That's a major jump!

I just pushed some changes to this repo and it increased JS performance by ~200k op/s on my machine. I have a new "math" mode incoming that is not crypto-safe but is 1M op/s faster.

@skuznetsov
Copy link

skuznetsov commented Mar 1, 2020

I was able to achieve even more impressive speed on my MacBook:

Crystal 0.33.0 (2020-02-14)

LLVM: 9.0.1
Default target: x86_64-apple-macosx
        UUIX:   5.92M (169.04ns) (±10.99%)  113B/op        fastest
Crystal UUID: 770.02k (  1.30µs) (± 3.55%)  0.0B/op   7.68× slower

This is with secure random buffer equal to 16MB and 1 byte shift (instead of original 16 as it is still unique and probability of generation of the same sequence is even less possible than with shift to 16) so it is quite good results with just 169 nanoseconds per one hash (including random data generation).
Also by some reason 16 MB buffer is fastest. sizes above and below are giving lower results.

@lukeed
Copy link
Owner

lukeed commented Mar 1, 2020

That's awesome! Let me see if I understand correctly:

You've modified this so that your window is inching along the pre-allocated Buffer 1 byte as a time (as opposed to a full chunk) 😂 That's so simple – great tweak!

var BUFFER = '123456...';

uuid(); // => '123...';
uuid(); // => '234...';
uuid(); // => '345...';

@lukeed
Copy link
Owner

lukeed commented Mar 1, 2020

Here are new numbers with that approach :)

  @lukeed/next                 x 6,447,983 ops/sec ±0.31% (93 runs sampled)
  @lukeed/uuid                 x 2,544,311 ops/sec ±0.30% (94 runs sampled)

@lukeed lukeed closed this as completed in 40c5517 Mar 1, 2020
@lukeed
Copy link
Owner

lukeed commented Mar 1, 2020

Hope you don't mind that I've closed this @krthr – only because it's not an "issue"

I really appreciate you porting this & sharing it! This is a first for me 🎉

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

No branches or pull requests

3 participants