mysterious performance gain

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 18 10:46:53 PDT 2014


On 07/18/2014 06:21 AM, Archibald wrote:

 > So I have this big, performance critical function that takes about 9
 > seconds to execute. If I add :
 >
 > double[] direct = new double[2];
 >
 > ... at the beggining of the function, with no further reference to this
 > array, suddenly it takes only 8 seconds.

Here is a wild guess: There is some undefined behavior because you are 
accessing locations on the stack that don't belong to you. When you 
introduce 'direct', it shifts the contents of the stack and the bytes 
that are used unintentionally are now different, which change the way 
the loop behaves.

Ali



More information about the Digitalmars-d-learn mailing list