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

Cached ID? #21

Closed szqmtl closed 5 years ago

szqmtl commented 5 years ago

Thanks for your library.

I wonder if you'd add a cached ID module, it might increase the performance.

Thanks again.

bwmarrin commented 5 years ago

My gut answer is, no. If you want to cache up a pile of IDs you can do that as a wrapper around this library.

However, I'm curious if you can give me some more context on why you need this? The library as it is now, is incredibly fast. What performance problems are you facing with it?

szqmtl commented 5 years ago

I don't have any issues with your implementation now or soon. Just curious to ask the question because, theoretically, it'd push the limit further.

Thanks again

bwmarrin commented 5 years ago

Well, if you ever get to that point you could write a tiny wrapper around this library that just farms ID's and caches them, then hands those out :) By default, it can dish out an ID every 243 milliseconds per node. If you adjust the bits you can get down to about 50milliseconds/ID per node. If you get where you need IDs faster than that - then I'll be excited to hear about what you've built!