From ec140e5f0f44e1a1c433dcc502be5117bc9dacd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20M=C3=A9lois?= Date: Mon, 14 Oct 2024 15:57:08 +0200 Subject: [PATCH] Optimise conversion from Blob to Stream (#1609) * Optimise conversion from Blob to Stream Motivated by https://github.com/http4s/http4s/issues/7539 * Updated changelog --- CHANGELOG.md | 4 ++++ .../http4s-kernel/src/smithy4s/http4s/kernel/package.scala | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3909041d..26434313f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ When adding entries, please treat them as if they could end up in a release any Thank you! +# 0.18.26 + +* Optimises the conversion of empty smithy4s.Blob to fs2.Stream, to avoid performance degradation in Ember (see [#1609](https://github.com/disneystreaming/smithy4s/pull/1609)) + # 0.18.25 * Add A flag to allow for numerics to be decoded from JSON strings (in smithy4s-json). diff --git a/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala b/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala index 690bf24ad..dee0c0424 100644 --- a/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala +++ b/modules/http4s-kernel/src/smithy4s/http4s/kernel/package.scala @@ -204,6 +204,8 @@ package object kernel { private def toStream[F[_]]( blob: Blob - ): Stream[F, Byte] = Stream.chunk(Chunk.array(blob.toArray)) + ): Stream[F, Byte] = + // Optimisation motivated by https://github.com/http4s/http4s/issues/7539 + if (blob.isEmpty) Stream.empty else Stream.chunk(Chunk.array(blob.toArray)) }