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

Optimize byte array operations in Http4sRequestBody #3772

Merged
merged 5 commits into from
May 20, 2024

Conversation

kciesielski
Copy link
Member

@kciesielski kciesielski commented May 17, 2024

This update optimizes how Stream[F, Byte] is handled.

  • For StringBody, instead of combining all chunks and copying the entire resulting byte array, I propose body.through(decodeWithCharset(...).compile.string, which decodes incoming byte chunks into smaller Strings, and then collects them efficiently into one final String using fs2's .string.
  • More importantly, for InputStreamBody and InputStreamBodyRange, I propose fs2.io.toInputStreamBody(body) to produce a lazily evaluated InputStream instead of fetching all bytes and returning them wrapped in a ByteArrayInputStream.

P.S. Similar optimization to StringBody can be adapted to netty-cats

@kciesielski kciesielski marked this pull request as draft May 17, 2024 11:58
@kciesielski kciesielski marked this pull request as ready for review May 17, 2024 12:10
@kciesielski kciesielski requested a review from adamw May 17, 2024 12:27
@adamw adamw merged commit 94b8b60 into master May 20, 2024
26 checks passed
@adamw adamw deleted the http4s-optimize-req-body branch May 20, 2024 08:08
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