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

In iterators, allocate new msg for each Receive #350

Merged
merged 1 commit into from
Aug 17, 2022
Merged

Conversation

akshayjshah
Copy link
Member

Currently, iterator-style streams re-use the same memory for each
received message. This is a satisfying little efficiency, but it's very
likely to cause confusion among users - they'll retain a reference to a
message, call Receive() again, and wonder why the retained reference
has changed out from under them. We should anticipate this confusion and
allocate for each Receive. As a nice side effect, this makes
vtprotobuf Codecs behave properly by default - no need to explicitly
reset messages.

This PR also adds a Conn() method to each stream that exposes the
underlying connection. This lets users who want a different high-level
stream API write their own wrapper types: perhaps they'd like to avoid
allocations more aggressively, or they want every stream constructor to
also require an auth token.

Fixes #345.

Currently, iterator-style streams re-use the same memory for each
received message. This is a satisfying little efficiency, but it's very
likely to cause confusion among users - they'll retain a reference to a
message, call `Receive()` again, and wonder why the retained reference
has changed out from under them. We should anticipate this confusion and
allocate for each `Receive`. As a nice side effect, this makes
`vtprotobuf` Codecs behave properly by default - no need to explicitly
reset messages.

This PR also adds a `Conn()` method to each stream that exposes the
underlying connection. This lets users who want a different high-level
stream API write their own wrapper types: perhaps they'd like to avoid
allocations more aggressively, or they want every stream constructor to
also require an auth token.

Fixes #345.
@akshayjshah akshayjshah merged commit 398f155 into main Aug 17, 2022
@akshayjshah akshayjshah deleted the ajs/mem branch August 17, 2022 15:15
@mattrobenolt
Copy link
Contributor

This is great, thank you. ❤️

alexandrem pushed a commit to alexandrem/connect-go that referenced this pull request Aug 17, 2022
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.

Don't reuse messages between Receive() calls
3 participants