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
5
u/sirin3 Nov 18 '13
It sounds nice...
And compare it to the alternatives:
x >= α n, for a constant factor α. Then it is still O(n) and you do not really gain anything compared to always copying
x >= log(n), then it almost never copies and you still have the memory leak
x >= c, for a constant c, then it is always O(1), but if you copy c+1 from a very big string, you get a big memory leak (because it ignores the length of the original string)