How fast is the JIT JIT compiler?

I heard a lot about how compiling JIT makes code work faster than precompiling when it comes to "long-running" applications. But how long does it take to fully optimize your application?

Just for fun, I'll show you an example. I have some method, let me call it mySlowMethod() . It performs some matrix calculations, such as rotation, multiplication, etc. A few hundred times per second. I measured the time of each call and got the following results:

 long time = System.nanoTime(); mySlowMethod(); System.out.println(System.nanoTime()-time); //first call 1577187 (1.6 ms) //next 2 seconds ~60000 (0.06 ms) //later less than 10000 (0.01 ms) 
+4
source share
1 answer

JIT actually works in a few small steps to minimize the impact of performance on application startup. These steps include:

  • Several modes.

    • The basic JIT compiler is used to perform [relatively] simple direct conversion of bytecode to machine code for immediate execution of individual methods.
    • An optimizing compiler is used to perform many advanced optimizations for code that runs multiple times and / or consumes a significant amount of computing resources.
  • Incremental compilation.

    • While the JVM loads the bytecode of entire modules in front, the actual compilation process is often delayed until the methods are executed for the first time. In large applications, for example, in the IDE, it is clear that not all IDE functions are used immediately when the application is launched, so this incremental compilation feature extends the JIT process by a much longer application run time to the point that it is often overlooked.

In general, the application is probably never โ€œfully optimized,โ€ but you will never know about it because the parts you really cared about were optimized before.

+5
source

Source: https://habr.com/ru/post/1488384/


All Articles