sony / sonyflake

A distributed unique ID generator inspired by Twitter's Snowflake
MIT License
3.89k stars 304 forks source link

Add DecomposeToBuffer() API to avoid allocating a map on hot paths #26

Closed kamstrup closed 2 years ago

kamstrup commented 3 years ago

Allocating a map[string]uint64 can be very expensive if called from a hot loop. Add a new function DecomposeToBuffer() that writes the ID components into a struct. The new function is implicitly covered by the existing tests because Decompose() uses it under the covers.

YoshiyukiMineo commented 2 years ago

Thank you for your feedback!

I have added new functions to get ID elements without memory allocation. https://github.com/sony/sonyflake/pull/35/files

kamstrup commented 2 years ago

Awesome - thanks! <3