I found it quite weird that it launched 4 threads and specially weird that it changed places (ChoosePixelFormat and SetPixelFormat) based on what code I called, and that the output log looked the same on them both:

Last week, I tried messing around with SDL and found that whenever I changed the window to use Opengl, it took the same 3 seconds to start. I tested that .exe in 4 different PCs. Two of them opened instantaneously, and two (the better two) took a long time.

I have a 64-bit Windows 10, running on an i7-5820K @3.30GHz and two GTX 780.

I'm running into the same problem, about 1.2 seconds for me. Some web searching digs up a number of posts about this issue, but no actual solutions. It does reek of a driver issue, but the issue seems widespread enough that finding a workaround would be highly desirable.

@mmozeiko I only use Windows Defender in this PC, it turned it off and added it to the exceptions list but there was no difference. I ended all the processes I could and no difference, so yeah, it's probably a driver problem.

It's somewhat reassuring that Nytheris and musicaljelly also have the problem. :P

Just to add some info, I tested on the drivers GeForce 382.05, 384.76 and 384.94.

After profiling, disassembling and debugging the driver, I found that most of the time it is processing huge list application & executable names. Not sure exactly what it is doing but its a lot of code+time. I think it tries to mach profile for custom 3D settings. In your Nvidia Control Panel go to "Manage 3D Settings" -> Program Settings -> uncheck "Show only programs found on this computer" and check how big is the list in combobox. It is huge.

Unfortunately there is no good way to officially delete contents of this list. I started to look where this list is stored and found three locations:

C:\ProgramData\NVIDIA Corporation\Drs\nvdrsdb0.bin

C:\ProgramData\NVIDIA Corporation\Drs\nvdrsdb1.bin

C:\Program Files\NVIDIA Corporation\Drs\nvdrsdb.bin

First two you can safely remove - but just in case DO NOT DELETE these files. Rename to something like nvdrsdb0.bin.old. It looks that these files store customized settings and are recreated from third location if they don't exist.

After removing first two files, the test program from my gist now prints 0.456 seconds. That is 32% improvement. Pretty nice.

Unfortunately we cannot remove or replace with empty file the third location. By doing that the Nvidia opengl driver will simply crash and none of your applications will work. What I did instead - I went to Nvidia site and took this file from old 280.26 driver version from 2011. There this file is only 305KB big compared to 1.4MB - so it stores less information about application settings. You can get this file here: nvdrsdb.zip You'll need to replace this file every time you upgrade Nvidia driver.

After replacing nvdrsdb.bin file my test program prints out 0.306 seconds which is ~54% - two times faster than initially. Even better!

Now it looks that Nvidia opengl code now is spending most of the time in different place, some initialization code with loading library (LoadLibrary function). Processing that big list is not a bottleneck anymore. Ideally I would want to reduce this list to 0 items, but that would require more time on reverse engineering format of nvdrsdb.bin file. I tried some quick'n'dirty experiments - replaced few numbers with value 0 in header, but all I got was crash. So more debugging is needed. But it should be possible.

I think Nvidia is just adding more and more predefined application profiles to this file, it gets bigger and bigger, so the linear scan through list gets slower and slower. Not 100% sure about this, that's just my guess.

I do not know if this breaks anything. Maybe your SLI configuration will stop working. Maybe there will be some glitches with older OpenGL applications/games - this file might contain some workarounds, not only 3D setting customizations. But try it, maybe it gets faster also for you. This is not a real fix, but for dev machine this could be acceptable workaround.

I ran your code and it printed 1.081.
So I went to the C:\Program Files\NVIDIA Corporation\Drs directory and there was no nvdrsdb0.bin or nvdrsdb0.bin!

Only nvdrsdb.bin and dbInstaller.exe.
After changing the nvdrsdb.bin file to the one you linked, I got a small performance increase to 1.077. :(

Over in the SDL thread, Daniel_Gibson linked to this tweet from Sean Barret: https://twitter.com/nothings/status/891335303130005504
Based on his tweet: "If NVIDIA folks following me want more info" I suppose Nvidia is already aware of the driver issue, and that it is actually pretty widespread (with different results, apparently). :P