vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.28k stars 418 forks source link

Store shuffled alphabets so that they don't have to be calculated again. #105

Closed jwpage closed 6 years ago

jwpage commented 6 years ago

This changes the Hashids::bench function so that it will store a shuffled alphabet once it's been created. This increases the performance of the function, especially when calculating large numbers of hashes.

Here are a couple of blackfire.io profiles for encoding 50,000 hashes.

vinkla commented 6 years ago

Thanks for the pull request @jwpage! This pull request looks good to me.

@ivanakimov what do you say?

jd327 commented 6 years ago

@vinkla @jwpage this is super awesome.

@jwpage thanks for providing benchmarks as well! I was trying to think of any scenarios where this might break anything, but I guess besides memory consumption if the tests are good, this should be a nice optimization.

@vinkla if looks good to you, let's get it out!

vinkla commented 6 years ago

Merged! This will be part of version 2.1 which will be released in the coming weeks. For now, you could set minimum-stability to dev and start using version 2.1 in development today.