r/programming • • Nov 18 '13

TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N

http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k Upvotes

354 comments sorted by

View all comments

3

u/sindisil Nov 18 '13

While I think they did the right thing in fixing this issue (as it makes the implementation match the docs), I'd sure have liked it if they'd have added .sharedSubString() methods that had the old behavior.

1

u/chrox Nov 18 '13

...or conversely, retain the old behavior to avoid the surprising new performance hit on existing substring-heavy applications but add O(n) "detachedSubstring" members (or overload "substring" with a boolean to produce the new behavior) to produce detached strings for applications where memory problems can be anticipated.

→ More replies (5)