hashids-java icon indicating copy to clipboard operation
hashids-java copied to clipboard

performance improvements

Open cazacugmihai opened this issue 7 years ago • 9 comments

This change is Reviewable

cazacugmihai avatar Feb 21 '18 18:02 cazacugmihai

Could you fix formatting, otherwise it's impossible to analyze the diff with so many changes. Thanks.

0x3333 avatar Feb 21 '18 19:02 0x3333

Also, if you could explain the performance improvements would help.

0x3333 avatar Feb 21 '18 19:02 0x3333

I have fixed the formatting.

The performance consists in:

  • using operations directly to the char arrays instead of using String;
  • some operations (like computing the validChars, guardsRegExp, sepsRegExp, regexp pattern) are precomputed and cached;
  • usage of StringBuilder instead of operating with strings (see StringBuilder buffer, ret_strB, StringBuilder hash , etc.);
  • adding a helper class (CharUtils) for working with char arrays.

cazacugmihai avatar Feb 21 '18 20:02 cazacugmihai

About the performance: I have gained about 100-200 ms for running all the tests (it is at least 20% more efficient).

cazacugmihai avatar Feb 21 '18 20:02 cazacugmihai

Great, I'll take some time to review and get back to you. Thanks.

0x3333 avatar Feb 21 '18 22:02 0x3333

About breaking this pull request in smaller pieces: I can't do this because the most part of it is related to the migration from String to char[]. I may extract the constants and the validation method but it will not help much reviewing the code (because those changes are only a couple of lines).

cazacugmihai avatar Feb 28 '18 17:02 cazacugmihai

@cazacugmihai what do you think about creating a branch and work on a new version? @gabrielhora you are invited to this discussion. I'll create an issue to work on that.

0x3333 avatar Feb 28 '18 19:02 0x3333

Sure, I can do that.

cazacugmihai avatar Feb 28 '18 19:02 cazacugmihai

Issue 55 - V2 Proposal. Let's discuss there before starting to code.

0x3333 avatar Feb 28 '18 19:02 0x3333