Enough java.lang.String to Hang Ourselves...
summary
Benchmarks compare "" + 42, Integer.toString and StringBuilder and show performance depends on JVM version not intuition, with Java 9+ using invokeynamic concatenation strategies where the default path allocates ~152 bytes while the old Java 5 pattern uses ~500 bytes and is ~2x slower. Memory tests show G1 String Deduplication can save roughly 40 bytes per duplicate and intern() is dangerous because the intern table is fixed. Java 7 removed substring sharing causing many char[] copies, and Java 9 replaces char[] with compact strings (byte[] + coder) which changes allocation and intrinsics behavior. GitHub repo contains the benchmarks.
AI-written summary · about
chapters (11)
- 0:00Start
- 2:55The Dark Ages
- 4:48Hash Code
- 18:16Compressed Strings
- 23:03Alternative Hashing Function
- 26:43Java 8
- 33:41Compact Strings
- 34:48String Concatenation
- 35:46Data Benchmarks
- 40:47Performance
- 41:30Byte Array
related talks
48mEnough java.lang.String to Hang Ourselves ...
46mEnough java.lang.String to Hang Ourselves ...
09mString Enhancements in JDK 9
40mWhat Every Java Programmer Should Know About Strings
51mRethinking Java String Concatenation
40mSave Java memory
45mHow difficult can it be to write efficient code?
41mJava 24, Faster Than Ever
