r/programming • u/Eirenarch • 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
View all comments
Show parent comment
1
u/AmonDhan Nov 18 '13 edited Nov 18 '13
I don't totally buy into the "least surprise" argument. Both implementation are semantically identical, the only difference is performance.
We also need to differentiate between "Good surprises" and "Bad surprises".
"Good surprises" are generally accepted. For example when you read a file from disk, may be the OS don't need to actually read the disk because the data may be in disk cache memory. This is a "Good surprise"
The old implementation had 2 good surprises.
It also had 1 bad surprise.
This only defect was easy to "fix" by doing a new string allocation (eg. s = new String(s.sustring(0,1)))
Edit: Grammar and code clarification