-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
UnPackTo disable merge by default #7527
Conversation
@RWauson FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is admirable that you are supporting both the "merge" and "reuse" use cases, but like I said in the linked issue, "reuse" was the intended use case from the start, and "merge" is a unintended niche use case.
Since supporting code complicates the code (generates more, and slower code), I personally would vote for only supporting reuse. But up to you.
My only reason to include it as an option is because I am switching defaults (I don't know when it was originally switched away from what we wanted). So having the parameter gives people an easy way to go back to the old way. |
That old way was never intended though, the amount of people relying on that behavior should be minimal. I'd be fine not supporting that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you feel the shrink_to_fit
is worth it? likely if something is reused, it will have a similar amount of elements, and shrink_to_fit
might entail alloc/copy/dealloc?
Yeah, I can remove the shrink to fit part. I also removed the |
…e memory leak The existing code relies on UnPackTo to merge the existing state with the new incoming state. However, this behavior was changed in google/flatbuffers#7527 and now leads to memory leak. Ignore the commit description there as it is outdated. During the review, they decided to not have the old behavior as an option. PiperOrigin-RevId: 484798857
* UnPackTo disable merge by default * avoid double free in test * remove merge parameter * remove shrink to fit
* UnPackTo disable merge by default * avoid double free in test * remove merge parameter * remove shrink to fit
Fixes: #7458
Adds a new field
bool _merge = false
toUnPackTo
that dictates if the receiving object's existing state is merged with the incoming state or not. When_merge == false
, it will reset any pointer in the receiving object to nullptr if there is nothing to unpack. For vectors, the vector is cleared (resized to 0) and then shrunk to reclaim memory.Previously, the merging of states was on by default, but I don't think that is the correct default value. See #7458 for background discussion. So this change makes merging off by default, and have to be explicitly opted in.
This is tested in two new tests that test with and without merging.