Performance questions
Java Urban Performance Legends
When is it important to set the default collection sizes?
- What is the time cost of growing an ArrayList?
- What is the time cost of growing/rehashing a HashMap with defaults from zero to 'n' entries?
- initial capacity 16, load factor .75
- growth algorithm if (size++ >= threshold) resize(2 * table.length)
- size should always be power of 2
- 0-1 million objects ? sec
- 0-10 million objects ? sec
- 0-20 million objects - it takes three times the current size to rehash since it doubles the internal array and copies the old array - with a 700M heap couldn't rehash 20 M objects without running out of memory
- 0-20 million objects with 1 GB heap ? sec
Is synchronization expensive?
- What is the time cost of un-contented synchronization?
- What is the time cost of contended synchronization?
When would pooling of objects yield significant performance gains?
- How much memory do empty objects require?
- How much time do objects take to create?
How close is the size of serialized objects, collections, and primitives to the actual in-memory size?
- Empty object
- byte
- short
- int
- long
- float
- double
- boolean
- char
- String
- HashMap
- Dual core, 2 GHz, 2 GB RAM
- Java 1.6.0-b105 client mode
- VM args -Xms700M -Xmx700M
- Tests warmed up VM
- Pre-created objects
- Measured and subtracted iteration time
Comments