bwmarrin / snowflake

A simple to use Go (golang) package to generate or parse Twitter snowflake IDs
BSD 2-Clause "Simplified" License
2.98k stars 371 forks source link

More readable and save CPU. #47

Closed CarsonSlovoka closed 1 year ago

CarsonSlovoka commented 2 years ago

You seem to be very busy, if there is anything that needs to improve, please let me know and I will try to save your time 😊

bwmarrin commented 1 year ago

@CarsonSlovoka Sorry.. I've struggled to keep up with github for the past few years. Kids and new job have consumed my life :)

But, I added some comments. On the monotonic clock issue there's another route I've learned about recently that we might be able to use. You can read about the issue here https://github.com/golang/go/issues/12914 and at the bottom you can see a link to https://github.com/aristanetworks/goarista/commit/46272bfb1c042fc2825d312fe33d494e9d13dd6b that shows a solution. This has become a popular solution in several other projects as well. It's quite a bit faster than time.Now() and it's a monotonic clock which is important for generating unique ID's in this package.