Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use much faster JDK utility for converting an int to a byte sequence. #163

Merged
merged 1 commit into from
Dec 17, 2015

Conversation

CodingFabian
Copy link
Contributor

At the moment Lettuce uses a private helper method accepting a long parameter to write the length of a String or byte array to redis.
First off, this length will be always "int",
secondly, the method uses a hand written StringBuilder and number % 10 algorithm to translate the long into a string.
It will produce a String 4321 for a length of 1234. This string will be reversed and the char values appended to the buffer.

The JDK however comes with the handy util Integer.toString(intValue) which will produce a correctly ordered String. This method is much faster and also benefits from improvements done to the JDK
(this was actually done quite recently: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-November/036765.html)

In summary this improves CPU and memory usage of this method.

mp911de added a commit that referenced this pull request Dec 17, 2015
@mp911de mp911de merged commit c7fa50e into redis:4.1 Dec 17, 2015
mp911de added a commit that referenced this pull request Dec 17, 2015
@mp911de
Copy link
Collaborator

mp911de commented Dec 17, 2015

Merged. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants