Speed tradeoff of Java's -Xms and -Xmx options

后端 未结 8 1811
北荒
北荒 2020-12-04 08:24

Given these two commands

A:

$ java -Xms10G -Xmx10G myjavacode input.txt

B:

$ java -Xms5G -Xmx5G myjavacode input.tx         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 09:09

    1. Allocation always depends on your OS. If you allocate too much memory, you could end up having loaded portions into swap, which indeed is slow.
    2. Whether your program runs slower or faster depends on the references the VM has to handle and to clean. The GC doesn't have to sweep through the allocated memory to find abandoned objects. It knows it's objects and the amount of memory they allocate by reference mapping. So sweeping just depends on the size of your objects. If your program behaves the same in both cases, the only performance impact should be on VM startup, when the VM tries to allocate memory provided by your OS and if you use the swap (which again leads to 1.)

提交回复
热议问题