Hello! I'm trying to understand what Burst can optimize and how so I tried this code :
[BurstCompile]
private static int BurstMandel(float x, float y, int iter)
{
int i = 0;
for (int _ = 0; _ < TIME_MULTIPLY; _++)
{
float z_real = 0;
float z_imag = 0;
float z_real_tmp;
float z_imag_tmp;
i = 0;
while (i < iter)
{
z_real_tmp = z_real * z_real - z_imag * z_imag + x;
z_imag_tmp = 2 * z_real * z_imag + y;
if (z_real_tmp * z_real_tmp + z_imag_tmp * z_imag_tmp >= 4) break;
z_real = z_real_tmp;
z_imag = z_imag_tmp;
i++;
}
}
return i;
}
I thought Burst would understand that the for loop is completely useless and just here to make it waste time (it just does the same exact thing TIME_MULTIPLY times, doing it once is enough to have the right result) but apparently it does not.
Not to criticize or anything like that, I'm just curious as to why 🙂
Is there something I'm doing wrong that causes it to not understand that? Or can it simply not do that kind of optimisations?
I'm even more surprised to see that, after trying the same in python, Numba (a python module)'s JIT compiler does see the optimization : no matter how much TIME_MULTIPLIER is, the function takes the same time 🙂
So it is apparently possible 🙂