by voidlogic · 12y ago · 0 comments
Letting a programmer use too much memory and have to learn why, and when to copy is much better than drastically changing the runtime characteristics of many existing programs. Not copying is way more efficient, you just need to be in the know-
There are even solution that can do both like conditional copying or keeping track of the parent and doing a conditional copy if needed at GC time.
I'm inclined to think that Java's old way of doing it is an optimization that largely became obsolete when the HotSpot VM came out over a decade ago. The nature of generational garbage collection means that the way this method ends up using memory in practice is rather different from what one might expect at first glance. Combine that with modern CPU architecture and it might even end up being faster because of better cache-friendliness.
>Last month, Java changed how it computes substrings.
... [tl;dr: previously always kept whole string, substring just stored indexes]
Java now uses a different method: always copying the substring.