-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: Release one copy of underlying data if the comparing result of two strings or two interfaces is true. #17526
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
Comments
This isn't a safe optimization for the compiler to do in the presence of multiple goroutines. It would also generate much larger code. If you want this behavior, you can write it explicitly yourself. |
this is not always feasible.
surely, it is not just to simply release one copy. The compiler should consider the safety.
Maybe yes, maybe not. I highly doubt the conclusion. |
The potentially unsafe thing is, that you need to modify a string, that could get modified concurrently. Say, e.g. Of course this isn't complete, but it illustrates the issue. There would need to be some locking around this optimization, which just makes it bonkers, because you pay synchronization cost on every string assign and comparison. |
Even if this could be implemented cheaply, compactly, and concurrency-safely, it's still not a sensible optimization. Consider:
If the compiler compiled the if-statement as:
then you would have stored a reference to |
@alandonovan btw, maybe keeping the long one is better. I can't make a conclusion now. |
@Merovius |
@yaxinlx what problem are you trying to solve? |
Assuming that the GC stops the world, of course. There's also issues with stack==heap, or equality between stack allocations from different frames. |
@alandonovan |
@dr2chase, |
This is not remotely feasible with our current implementation. There is no stop-the-world pass that can modify local variables. There is no support for pointer chasing. I think that leaving this closed is correct. If the architecture of the system changes significantly--for example, if we implement a moving garbage collector, which we currently have no plans to do--we can revisit. |
@ianlancetaylor It is ridiculous to give up an improvement just for there is not a simple good implementation at current time. Does this improvement break the compatibility? Finally, if go team really think this improvement is pointless, |
There are far too many open issues already. Every open issue is a drag on the project, as we must periodically review it and see if we can move it along. I don't think it is useful to leave open issues for ideas that we don't think can be implemented. |
What version of Go are you using (
go version
)?go version go1.7.1 linux/amd64
What did you do?
https://play.golang.org/p/Lu9FZ9iqn6
https://play.golang.org/p/-wE2oUGce1
What did you expect to see?
much memory should be released after the comparing.
What did you see instead?
no memory released.
The text was updated successfully, but these errors were encountered: