Say you have a bunch of nested loops.
public void testMethod() {
for(int i = 0; i<1203; i++){
//some computation
for(int k=2; k<123; k++){
//some computation
for(int j=2; j<12312; j++){
//some computation
for(int l=2; l<123123; l++){
//some computation
for(int p=2; p<12312; p++){
//some computation
}
}
}
}
}
}
When the above code reaches the stage where the compiler will try to optimize it (I believe it's when the intermediate language needs to converted to machine code?), what will the compiler try to do? Is there any significant optimization that will take place?
I understand that the optimizer will break up the loops by means of loop fission. But this is only per loop isn't it? What I mean with my question is will it take any action exclusively based on seeing the nested loops? Or will it just optimize the loops one by one?
If the Java VM complicates the explanation then please just assume that it's C or C++ code.
some computation
inside it does almost nothing. Optimizing has benefit in code only to the proportion that the program counter actually spends time in it. Of course, compilers do a lot of unnecessary optimization.