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

Improve Performance of ASCII Integer Writing into ByteBuffer #9

Open
dkz2 opened this issue May 22, 2023 · 0 comments
Open

Improve Performance of ASCII Integer Writing into ByteBuffer #9

dkz2 opened this issue May 22, 2023 · 0 comments

Comments

@dkz2
Copy link
Contributor

dkz2 commented May 22, 2023

We currently are converting integers to strings and then writing them as ASCII to the ByteBuffer.

let string = String(integer)
self.writeString(string)

This is b/c the Memcached meta command protocol is text based and commands are send as ASCII strings.
Sending binary data would lead to an error for example: the command ms foo 2 would be incorrectly serialized as ms foo \0\0\0\0\0\0\0\u{2} if we used writeInteger.

However, this string conversion is not the most performant solution and could potently slow down our API. we would like to explore more efficient ways of writing the integer as ASCII digits directly to the ByteBuffer, bypassing the string conversion all together.

There are two possible solutions thus far that we are considering.

  1. We could write everything into a big tuple and then reverse write them into the byte buffer
  2. We could write everything in reverse into the byte buffer and then just swap the bytes around.

The second options is promising as it Is easier to implement and can also leverage swifts quotientAndRemainder method to perform the Integer division and modules in one go.

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

No branches or pull requests

1 participant