Is it true that having lots of small methods helps the JIT compiler optimize?

后端 未结 4 458
夕颜
夕颜 2021-01-30 16:56

In a recent discussion about how to optimize some code, I was told that breaking code up into lots of small methods can significantly increase performance, because the JIT compi

4条回答
  •  灰色年华
    2021-01-30 17:08

    I don't really understand how it works, but based on the link AurA provided, I would guess that the JIT compiler will have to compile less bytecode if the same bits are being reused, rather than having to compile different bytecode that is similar across different methods.

    Aside from that, the more you are able to break down your code into pieces of sense, the more reuse you are going to get out of your code and that is something that will allow optimization for the VM running it (you are providing more schema to work with).

    However I doubt it will have any good impact if you break your code down without any sense that provides no code reuse.

提交回复
热议问题