From my experience, it is related with Low-fragmentation Heap. But you said you have set _NO_DEBUG_HEAP=1, so I don't know if this is the right answer, I think you at lease can give a try.
The low-fragmentation heap (LFH) helps to reduce heap fragmentation, when enabled, it can boost the performance of your application with 10X speed increase if your application use a lot of memory allocations.
LFH is enabled by default starting with Windows Vista, however, LFH is disabled When a process is run under any debugger, certain heap debug options are automatically enabled for all heaps in the process. These heap debug options prevent the use of the LFH.
This explains why the application runs 10x slower if launched from VS.(I encountered the same problem in the past). you can use the function HeapQueryInformation to the get heap information and output it to verify if it is caused by LFH disabled.
For details of LFH, refer these two articles:
- Low-fragmentation Heap
- HeapSetInformation function
One similar post on the forum: Why does my STL code run so slowly when I have the debugger/IDE attached?