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

s3: avoid array copies when dealing with ByteStrings #658

Merged
merged 2 commits into from
May 21, 2024

Conversation

pjfanning
Copy link
Contributor

the 'unsafe' methods are ok if you know the data is not being mutated

@pjfanning pjfanning requested a review from mdedetrich May 16, 2024 19:36
@pjfanning
Copy link
Contributor Author

@mdedetrich You are the most active contributor to the S3 code base. Do these changes look ok to you?

@@ -36,7 +36,16 @@ package object auth {
new String(out)
}

@InternalApi private[impl] def encodeHex(bytes: ByteString): String = encodeHex(bytes.toArray)
@InternalApi private[impl] def encodeHex(bytes: ByteString): String = {
val length = bytes.length
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ByteString implements IndexedSeq[Byte] so we can iterate it without converting it to an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the ByteStrings code (complex ByteString made up of underlying ByteStrings) the apply(Int) function and the iterator function are not performant.

https://github.com/apache/pekko/blob/c4805f1839ead0cfe31700d6c41928df9fb1056d/actor/src/main/scala-3/org/apache/pekko/util/ByteString.scala#L554-L570

So I'm now thinking of changing this to

def encodeHex(bytes: ByteString): String = encodeHex(bytes.toArrayUnsafe)

Copy link
Contributor

@nvollmar nvollmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@laglangyue
Copy link
Contributor

lgtm

@pjfanning pjfanning merged commit 473c5e1 into apache:main May 21, 2024
51 checks passed
@pjfanning pjfanning deleted the s3-hex branch May 21, 2024 09:46
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.

None yet

3 participants