Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kyri-petrou
Copy link
Contributor

/fixes #9935
/claim #9935

Main issue is that charBuffer.flip() was being called just once (see comment below), so in case that we couldn't drain the charBuffer in a single iteration, we were not flipping it in the next iteration causing an infinite loop (and eventually an OOM error).

I also took the opportunity to re-write this method using tail recursion instead of ZIO recursion which should be far more performant

def endOfInput(): Chunk[Byte] = {
@tailrec
def loop(acc: Chunk[Byte] = Chunk.empty): Chunk[Byte] = {
charBuffer.flip()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main fix. Everything else is optimizations

@kyri-petrou kyri-petrou merged commit e9c8d7e into zio:series/2.x Jul 7, 2025
19 checks passed
@kyri-petrou kyri-petrou deleted the avoid-oom-encoding-zpipeline branch July 7, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZPipeline.encodeCharsWith method from zio-streams causes memory leaks

2 participants