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

s2: Proposal: Callback when done with EncodeBuffer #981

Closed
Jille opened this issue Jul 25, 2024 · 3 comments · Fixed by #982
Closed

s2: Proposal: Callback when done with EncodeBuffer #981

Jille opened this issue Jul 25, 2024 · 3 comments · Fixed by #982

Comments

@Jille
Copy link
Contributor

Jille commented Jul 25, 2024

Buffers given to s2.Writer.EncodeBuffer() can't be touched until a full Flush/Close is done, while the buffer is probably reusable much sooner.

What would you think of a WriterOption that installs a callback that is invoked whenever it is safe to reuse the buffer given to EncodeBuffer?

I'm thinking func WriterEncodeBufferCallback(callback func([]byte)) WriterOption.

The common use case would be to return the buffer to a sync.Pool. I want to pass data straight from a ringbuffer-of-bytes into EncodeBuffer and want to know when I can mark it as freed.

I'll be happy to write up the PR if you agree with this proposal.

@klauspost
Copy link
Owner

Seems feasible.

klauspost added a commit that referenced this issue Jul 26, 2024
WriterBufferDone will perform a callback when EncodeBuffer has finished
writing a buffer to the output and the buffer can safely be reused.

If the buffer was split into several blocks, it will be sent after the last block.

Callbacks will not be done concurrently.

Fixes #981
@klauspost
Copy link
Owner

See #842

@Jille
Copy link
Contributor Author

Jille commented Jul 26, 2024

Nice, thank you!

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 a pull request may close this issue.

2 participants