Skip to content

Conversation

@darshankparmar
Copy link
Contributor

This PR reduces memory churn in StreamBuffer.read() by reusing the existing BytesIO buffer instead of reallocating a new one after each read.

self._buffer.seek(0)
self._buffer.truncate()
self._buffer.write(remaining)
self._buffer.seek(0)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this works.

would future bytes be written at 0? overwriting remaining? reading and writing are happening at the same position, which isn't what we want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this works.

would future bytes be written at 0? overwriting remaining? reading and writing are happening at the same position, which isn't what we want

Thanks for the review. After a deeper look, you’re right.

While the truncate-based approach reduces allocations, it relies on implicit BytesIO cursor behavior and isn’t robust enough for a concurrency primitive.
Alternative designs (e.g. ring buffers) would break PyAV’s file-like contract or require a larger redesign.

I’ll revert this change and keep the existing behavior for correctness.

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