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

Remove IO.blocking from array copy in S3 client. #1265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LeifW
Copy link

@LeifW LeifW commented Nov 13, 2024

  • Also remove the array copy - using .asByteArrayUnsafe instead of .asByteArray to return the original byte array without making a copy of it. FS2 doesn't mutate the byte array afaict, and this readFileMultipart method returns a fs2.Stream[F, Byte] - the caller isn't going to be able to mutate those Bytes.

  • Also removed the Monad.ifM. ifM(pure(x))(t, f) is the same as if (x) t else f.

  • Construct the Chunks from byte arrays in a more direct fashion.

Async[F].blocking {
val bs = resp.asByteArray()
val len = bs.length
if (len < 0) None else Some(Chunk(unsafeWrapArray(bs)*))
Copy link
Author

Choose a reason for hiding this comment

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

Also, why are we checking to see if the array size is negative? What would that even mean? This SO post says that can't happen: https://stackoverflow.com/a/11530038/283260
Should this just always return Some?

Copy link
Author

Choose a reason for hiding this comment

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

Pushed a second commit removing this length check.

Leif Warner added 2 commits November 13, 2024 12:14
* Also remove the array copy - using `.asByteArrayUnsafe` instead of
`.asByteArray` to return the original byte array without making a copy
of it. FS2 doesn't mutate the byte array afaict, and this
`readFileMultipart` method returns a `fs2.Stream[F, Byte]` - the caller
isn't going to be able to mutate those Bytes.

* Also removed the `Monad.ifM`. `ifM(pure(x))(t, f)` is the same as `if
(x) t else false`.

* Construct the `Chunk`s from byte arrays in a more direct fashion.
Consolidate two subsequent `.flatMap`s into one.
@LeifW LeifW force-pushed the remove_blocking_and_array_copy branch from db2d22e to b7d78a3 Compare November 13, 2024 20:15
Async[F].pure((Option.empty[ETag], Option.empty[Checksum], Option.empty[PartId]))
)
cancelUpload(uploadId) *> (
if (uploadEmptyFiles) uploadEmptyFile.map(eTag => Option(eTag.eTag))
Copy link
Author

Choose a reason for hiding this comment

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

Could also do these two lines w/ like a OptionT.whenF(uploadEmptyFiles)(uploadEmptyFile), etc...

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.

1 participant