A DESCRIPTION OF THE REQUEST :
J2SE 5 has an optimization that converts string concatenation to StringBuilder.append calls automatically.
The problem is that these optimization use the default StringBuilder constructor, which has its initial capacity hardcoded to 16. This is a value which is way too low for existing implementations (which use string concatenation) and this causes lots of unneeded calls to StringBuilder.extendCapacity(). Under load, these calls waste both CPU time and memory.
My suggestion is divided to two:
1. Allow the default StringBuilder capacity to be read from a system property, so specific implementations can tune this value to minimize extra expandCapacity() calls
2. The java compiler optimization should take the length of literal strings into account when performing this optimization - For example, if
JUSTIFICATION :
This will prevent many unneeded calls to expandCapacity(), which waste CPU time and memory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1. Default capacity of StringBuilder is configurable through a system property.
2. Java compiler optimization taken into account the total length of literals when converting string concatenation to StringBuilder.append() calls.
ACTUAL -
1. StringBuilder default capacity is hardcoded in the class file.
2. Java Compiler calls default StringBuilder constructor without taking literal string lengths into account.
J2SE 5 has an optimization that converts string concatenation to StringBuilder.append calls automatically.
The problem is that these optimization use the default StringBuilder constructor, which has its initial capacity hardcoded to 16. This is a value which is way too low for existing implementations (which use string concatenation) and this causes lots of unneeded calls to StringBuilder.extendCapacity(). Under load, these calls waste both CPU time and memory.
My suggestion is divided to two:
1. Allow the default StringBuilder capacity to be read from a system property, so specific implementations can tune this value to minimize extra expandCapacity() calls
2. The java compiler optimization should take the length of literal strings into account when performing this optimization - For example, if
JUSTIFICATION :
This will prevent many unneeded calls to expandCapacity(), which waste CPU time and memory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1. Default capacity of StringBuilder is configurable through a system property.
2. Java compiler optimization taken into account the total length of literals when converting string concatenation to StringBuilder.append() calls.
ACTUAL -
1. StringBuilder default capacity is hardcoded in the class file.
2. Java Compiler calls default StringBuilder constructor without taking literal string lengths into account.
- relates to
-
JDK-4059189 Compiler generated code for String.operator+() could avoid allocations.
- Closed