Performance Impact of Object Size

This section provides tests to find out performance impact of the object size. Java manages larger objects more efficiently for the same total amount of data.

Since JDK is using G1 garbage collector with a 1024K region size by default, the object size may have a significant impact on the performance. Let's run some tests to find out.

Test 1 - Running GCPerformance.java with object size of 384K which is less than half of the G1 heap region size. So normal eden and survivor regions will be used. Chunk size is set to 128 to ensure that each junk takes multiple milliseconds to run.

herong> java -Xms1600m -Xmx1600m GCPerformance 384 64 128 0 64

Parameters: Size=384KB, Base=64, Chunk=128, Wait=0ms, Warmup=64
Real:Exec  Lat.     Throughput      Total:Free  Proc.
Time:Time  ms/o  Ave:Min:Max:Chunk   Mem.:Mem.   Obj.
8:8  62  16000:16000:16000:16000  1638400:1239167  128
44:44  281  5818:3555:16000:3555  1638400:1172991  256
55:55  281  6981:3555:16000:11636  1638400:1107455  384
67:67  281  7641:3555:16000:10666  1638400:1041919  512
79:79  281  8101:3555:16000:10666  1638400:976383  640
91:91  281  8439:3555:16000:10666  1638400:910847  768
115:115  281  7791:3555:16000:5333  1638400:1254527  896
127:127  281  8062:3555:16000:10666  1638400:1188991  1024
139:139  281  8287:3555:16000:10666  1638400:1123455  1152
151:151  281  8476:3555:16000:10666  1638400:1057919  1280
163:163  281  8638:3555:16000:10666  1638400:992383  1408
175:175  281  8777:3555:16000:10666  1638400:926847  1536
187:187  281  8898:3555:16000:10666  1638400:861311  1664
199:199  281  9005:3555:16000:10666  1638400:795775  1792
211:211  281  9099:3555:16000:10666  1638400:730239  1920
223:223  281  9183:3555:16000:10666  1638400:664703  2048
243:243  281  8954:3555:16000:6400  1638400:1239728  2176
                              ----
       Maybe GC performed here - |
255:255  281  9035:3555:16000:10666  1638400:1174192  2304
...
9066:9066  281  10108:3555:16000:10666  1638400:846488  91648

Test 2 - Increasing object size to 768K which slightly greater than than half of the G1 heap region size. So humongous regions will be used.

herong> java -Xms1600m -Xmx1600m GCPerformance 768 64 128 0 64

Parameters: Size=768KB, Base=64, Chunk=128, Wait=0ms, Warmup=64
Real:Exec  Lat.     Throughput      Total:Free  Proc.
Time:Time  ms/o  Ave:Min:Max:Chunk   Mem.:Mem.   Obj.
24:24  187  5333:5333:5333:5333  1638400:916178  128
68:68  343  3764:2909:5333:2909  1638400:1440403  256
88:88  343  4363:2909:6400:6400  1638400:1309331  384
112:112  343  4571:2909:6400:5333  1638400:1178259  512
136:136  343  4705:2909:6400:5333  1638400:1047187  640
156:156  343  4923:2909:6400:6400  1638400:916115  768
184:184  343  4869:2909:6400:4571  1638400:1440389  896
208:208  343  4923:2909:6400:5333  1638400:1309317  1024
232:232  343  4965:2909:6400:5333  1638400:1178245  1152
252:252  343  5079:2909:6400:6400  1638400:1047173  1280
276:276  343  5101:2909:6400:5333  1638400:916101  1408
304:304  343  5052:2909:6400:4571  1638400:1440389  1536
328:328  343  5073:2909:6400:5333  1638400:1309317  1664
352:352  343  5090:2909:6400:5333  1638400:1178245  1792
...
23321:23321  343  5340:2909:6736:5333  1638400:1309345  124544

Test 3 - Increasing object size to 1536K which slightly greater than than half of the G1 heap region size. So multiple humongous regions per object will be used.

herong> java -Xms1600m -Xmx1600m GCPerformance 1536 64 128 0 64

Parameters: Size=1536KB, Base=64, Chunk=128, Wait=0ms, Warmup=64
Real:Exec  Lat.     Throughput      Total:Free  Proc.
Time:Time  ms/o  Ave:Min:Max:Chunk   Mem.:Mem.   Obj.
48:48  375  2666:2666:2666:2666  1638400:1243920  128
120:120  562  2133:1777:2666:1777  1638400:980750  256
172:172  562  2232:1777:2666:2461  1638400:1243843  384
216:216  562  2370:1777:2909:2909  1638400:981699  512
264:264  562  2424:1777:2909:2666  1638400:1243845  640
312:312  562  2461:1777:2909:2666  1638400:981701  768
360:360  562  2488:1777:2909:2666  1638400:1243841  896
408:408  562  2509:1777:2909:2666  1638400:981697  1024
456:456  562  2526:1777:2909:2666  1638400:1243845  1152
504:504  562  2539:1777:2909:2666  1638400:981701  1280
552:552  562  2550:1777:2909:2666  1638400:1243843  1408
599:599  562  2564:1777:2909:2723  1638400:981699  1536
647:647  562  2571:1777:2909:2666  1638400:1243845  1664
...
15334:15334  562  2671:1777:2976:2666  1638400:981666  40960

Test result summary

                                      Normalized to 384K
Object Size   Latency   Throughput   Latency   Throughput
-----------   -------   ----------   -------   ----------
      1536K       562         2671       141        10684
       768K       343         5340       172        10680
       384K       281         9035       281         9035

Takeaways: Java manages larger objects more efficiently for the same total amount of data.

Table of Contents

 About This Book

 Heap Memory Area and Size Control

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

 Serial Collector - "+XX:+UseSerialGC"

 Parallel Collector - "+XX:+UseParallelGC"

 Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 The Z Garbage Collector (ZGC) - "+XX:+UseZGC"

 Object References and Garbage Collection

Garbage Collection Performance Test Program

 GCPerformance.java - GC Performance Test Program

 GCPerformance.java - Program Output

 Performance Impact of Wait Time

Performance Impact of Object Size

 Performance Impact of Chunk Size

 Performance Jumps Not Related to GC

 Performance Test and System Interruptions

 "START /REALTIME" - Run JVM with Highest Priority

 GCPerfP99.java - 99th Percentile Performance

 GCPerfP99.java - Output Verification

 GCPerfP99V2.java - Percentile Performance with Load

 GCPerfP99V2.java - Work Load Level

 GCPerfP99V2.java - Object Number and Size

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 References

 Full Version in PDF/EPUB