Skip to content

x/printer: serialize writes and reuse buffer #63

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

Merged
merged 2 commits into from
Apr 2, 2025

Conversation

zombiezen
Copy link
Contributor

io.Writer implementations are not guaranteed to support writes from multiple concurrent goroutines. However, users of kawa.Destination implicitly assume that Send is safe to call concurrently. (I'm working to document that assumption.) I added a channel-based mutex to serialize the writes (and allow cancellation), plus have a reusable buffer so that each batch can be performed in a single Write. (This lowers syscall overhead.)

Add doc comments for exported symbols.

`io.Writer` implementations are not guaranteed to support writes from multiple concurrent goroutines.
However, users of `kawa.Destination` implicitly assume that `Send` is safe to call concurrently.
(I'm working to document that assumption.)
I added a channel-based mutex to serialize the writes
(and allow cancellation),
plus have a reusable buffer so that each batch can be performed in a single `Write`.
(This lowers syscall overhead.)

Add doc comments for exported symbols.
@zombiezen zombiezen requested a review from abraithwaite March 31, 2025 21:07
Copy link
Member

@abraithwaite abraithwaite left a comment

Choose a reason for hiding this comment

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

Great catch, thanks!

Added tests to isolate issue.
@zombiezen zombiezen merged commit 6d740fd into runreveal:main Apr 2, 2025
1 check passed
@zombiezen zombiezen deleted the sync-printer branch April 2, 2025 20:36
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