Skip to content

Improve Performance of ASCII Integer Writing into ByteBuffer #9

Open
@dkz2

Description

@dkz2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions