-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 7
-
Component/s: core-libs
-
None
-
b77
-
generic
-
generic
Description:
- A list of size N should create only N+1 objects, not N+2.
- Use of null as sentinel value instead of a sentinel (Null Object)
is slightly less convenient, but is measurably faster, since hotspot
has to insert null checks (with NPE throws) anyways.
- generify
- warning removal
- gratuitous tests added.
- cosmetic doc improvements
- the original motivation for this was to have a O(1) clear,
but we eventually decided against that
- but we documented our decision.
Below is a stupid microbenchmark demonstrating app. a factor of 2 improvement in
"throughput", anda 50% improvement in memory footprint
public class LinkedListBench {
public static void main(String[] args) {
LinkedList spine = new LinkedList();
long i = 0;
long t0 = System.nanoTime();
try {
for (i = 0; ; i++) {
spine.add(new LinkedList());
}
} catch (OutOfMemoryError e) {
spine.clear();
System.out.printf("allocated = %d%n", i);
System.out.printf("ns/object = %d%n", (System.nanoTime()-t0)/i);
}
}
}
see
http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-November/003135.html
- A list of size N should create only N+1 objects, not N+2.
- Use of null as sentinel value instead of a sentinel (Null Object)
is slightly less convenient, but is measurably faster, since hotspot
has to insert null checks (with NPE throws) anyways.
- generify
- warning removal
- gratuitous tests added.
- cosmetic doc improvements
- the original motivation for this was to have a O(1) clear,
but we eventually decided against that
- but we documented our decision.
Below is a stupid microbenchmark demonstrating app. a factor of 2 improvement in
"throughput", anda 50% improvement in memory footprint
public class LinkedListBench {
public static void main(String[] args) {
LinkedList spine = new LinkedList();
long i = 0;
long t0 = System.nanoTime();
try {
for (i = 0; ; i++) {
spine.add(new LinkedList());
}
} catch (OutOfMemoryError e) {
spine.clear();
System.out.printf("allocated = %d%n", i);
System.out.printf("ns/object = %d%n", (System.nanoTime()-t0)/i);
}
}
}
see
http://mail.openjdk.java.net/pipermail/core-libs-dev/2009-November/003135.html
- relates to
-
JDK-4679639 (coll) Optimization for LinkedList's indexOf and lastIndexOf methods
-
- Closed
-