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

Show parent comment

4

u/[deleted] Nov 18 '13

Changing complexity from constant to linear is a terrible thing to do

The substring routines in most languages have linear complexity, and it's not considered terrible. Substring referencing was an optimization, which turned out to cause memories leaks. You load a config file into memory, pull out the 8 characters you need, and the entire buffer is held forever. You cache one word from each network message in a high speed communication channel, and the entirety of every message stays in memory forever. That's bad. They fixed it by removing an optimization that was never documented to begin with.