Sources of Java Performance Problems
Example of API object creations/copy operations in API: consider ByteArrayOutputStream, frequently used in programs reading byte streams from sockets
- contains a byte[] array as internal buffer; on reference platform, creating buffer takes 164 ms per kB
- writing data into object with write(byte[] b, int off, int len) copies b into buffer; buffer reallocation and expansion (= object allocation + copy operation) necessary when previous + new data exceeds buffer capacity
- reading buffer contents with toString() or toByteArray() means allocating String or byte[] array and copying buffer contents into it