Java performance tips

前端 未结 14 1747
傲寒
傲寒 2021-02-01 20:04

I have a program I ported from C to Java. Both apps use quicksort to order some partitioned data (genomic coordinates).

The Java version runs fast, but I\'d like to get

14条回答
  •  轮回少年
    2021-02-01 20:51

    Don't optimize prematurely.

    Measure performance, then optimize.

    Use final variables whenever possible. It will not only allow JVM to optimize more, but also make your code easier to read and maintain.

    If you make your objects immutable, you don't have to clone them.

    Optimize by changing the algorithm first, then by changing the implementation.

    Sometimes you need to resort to old-style techniques, like loop unrolling or caching precalculated values. Remember about them, even if they don't look nice, they can be useful.

提交回复
热议问题