features/pool: clear repeated bytes/string field in ResetVT#152
Merged
vmg merged 4 commits intoplanetscale:mainfrom Mar 13, 2025
Merged
features/pool: clear repeated bytes/string field in ResetVT#152vmg merged 4 commits intoplanetscale:mainfrom
vmg merged 4 commits intoplanetscale:mainfrom
Conversation
In newer version of Go, the SVC build information are always added by default. Thus causing `make genall` to generate test files with a different "protoc-gen-go-vtproto version" line. Setting `-buildvcs=false` explicitely ensure that we keep using `(devel)` for the version info.
Clearing repeated bytes/string field ensure that the memory can be released by the garbage collector. Previously, the slice was only resized to 0, but the underlying []byte/string were still referenced by the slice. String are immutable in Go and aren't supposed to be modified after they are created, so reusing the allocated memory is not possible. The memory allocated for []byte could be reused, but this requires some additional modification to the generated Unmarshal code and would be incompatible with the use of UnmarshalVTUnsafe. This could be considered in a follow-up PR. When repeating other types, we don't need to clear the slices: - scalar: the slice itself hold the memory - embedded messages: `.Reset` or `.ResetVT` is being called instead to clear the message. `clear()` was introduced in Go 1.21, so the version has to be bumped.
vmg
approved these changes
Mar 13, 2025
Contributor
vmg
left a comment
There was a problem hiding this comment.
Thank you, this was indeed a memory leak. Very good catch!
Signed-off-by: Vicent Marti <vmg@strn.cat>
|
We haven't had a release since Jan 2024. Can we do a new release please? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clearing repeated bytes/string field ensure that the memory can be
released by the garbage collector. Previously, the slice was only
resized to 0, but the underlying []byte/string were still referenced
by the slice.
String are immutable in Go and aren't supposed to be modified after they
are created, so reusing the allocated memory is not possible. The memory
allocated for []byte could be reused, but this requires some additional
modification to the generated Unmarshal code and would be incompatible
with the use of UnmarshalVTUnsafe. This could be considered in a
follow-up PR.
When repeating other types, we don't need to clear the slices:
.Resetor.ResetVTis being called instead toclear the message.
clear()was introduced in Go 1.21, so the version has to be bumped.