What LDC flags should be used to get the fastest executable on Windows?

Dennis dkorpel at gmail.com
Sat Mar 6 14:56:00 UTC 2021


On Saturday, 6 March 2021 at 13:45:42 UTC, Preetpal wrote:
> I am kind of skeptical that this problem is performance-related 
> as well but based on the decreased number of times that this 
> problem occurred during my usage of the C version of program 
> versus the D version that was not compiled with as aggressive 
> optimization flags, it suggests that this is a performance 
> problem.

Have you compared your C version with and without optimization 
flags?
If that makes a difference, I think it's a race condition. Though 
optimization flags might change the timing and mask away the 
issue, it doesn't really solve the problem.
A performance problem would be if your hook function actually 
took near 300 ms to complete, but that doesn't seem the case here.

> Well I created the following test program on 
> https://godbolt.org to see what kind of difference __gshared 
> makes:

I didn't suggest __gshared because it is faster, I suggested 
because I don't know which thread calls your callback function. 
If SetWindowsHookEx makes the calls to the callback from 
different threads, then different instances of your variables 
will be read / written to. So maybe Thread A sets shiftPressed = 
true, and Thread B sets shiftPressed = false, and then Thread A 
still reads shiftPressed = true when executing 
detectAndActivateShortcut.


More information about the digitalmars-d-ldc mailing list