Page 1 of 1

OpenGL initialization performance

Posted: Mon Oct 27, 2014 11:28 am
by 16469855
Hi

I know that OpenGL need some time to perform initialization but is it possible to do it without freezing main thread? It's very annoying when I have to wait 2-4 seconds until main window will respond.

Paul

Re: OpenGL initialization performance

Posted: Mon Oct 27, 2014 3:53 pm
by 16567885
I also wondered the same. It's really taking a lot of time.
In case it has to be the main thread, is it possible to do it in advance? I'd like to do it when my application starts up. For now, it seems to be delayed until the chart becomes visible.

Re: OpenGL initialization performance

Posted: Fri Oct 31, 2014 1:12 pm
by 10050769
Hello Paul and Jens,

I would like inform you that we are investigating about the performance problem you are experiencing we try to give you a good answer in shortest time as possible.

Thanks in advance,

Re: OpenGL initialization performance

Posted: Tue Nov 04, 2014 9:35 am
by yeray
Hello,

Find here a simple test project we made to check the OpenGL initialization times.
This example only uses a TDraw3D and creates the GLCanvas to measure the initialization time.
GL_Init.zip
(2.42 KiB) Downloaded 1261 times
Here the results we got:

Delphi 7, Run
First run: 9328 millisec
Second run: 6469 millisec

Delphi 7, Running exe directly to avoid debugging
First run: 922 millisec
Second run: 469 millisec

XE7, Run
First run: 6360 millisec
Second run: 6500 millisec

XE7, Run without debugging
First run: 1047 millisec
Second run: 469 millisec

Note a big difference is noticeable between running the project with or without debug mode "Run without debugging".
The test project uses 3 fonts (Arial, Verdana i Courier New). Using one makes it considerably faster.

Also note the tests here have given very similar results when building&running the project for 32 and 63 bits in XE7.

If your times you get are much bigger, it may be due to hardware / driver.
Here the machine specifications we made the tests above with:
OS:Windows 8.1 64-bit
CPU: Intel Core i7-4771 @3.5GHz CPU
Memory: 16GB RAM
Primary drive: Samsung SSD 840 EVO
Graphics: NVIDIA GeForce GTX 760

Also note the Nvidia / Raedon control panels include some 3D settings globally used in all the applications or modifiable for a specific application or exe.

Re: OpenGL initialization performance

Posted: Tue Nov 04, 2014 9:40 am
by 16567885
Thanks for the Benchmark.

But please note that both of us were perfectly fine with the OpenGL initialization taking a bit of time. Our main gripe was the fact the main thread is blocked. If it really has to be the main thread, please give us a way to do it in advance.

When, for example, the TChart is put on a TPageControl and the user then switches to the chart, the whole application locks up. I'd be perfectly fine with the chart taking its time at application startup but not when the user has started working. :)


Oh and by the way: On my way slower machine it's 1840ms vs. 358ms with XE7 ;-)


Update:
That code example is very useful! :!: :mrgreen:

I did some further profiling- The InitWindow command takes at least half of the time, the font stuff at least a third. The other parts are negligible :)
So:
  • Thanks for showing us the TGLCanvas::InitWindow(..) command. That looks like pretty much what I was looking for
  • Can you elaborate on the font stuff? Why is the number of different fonts used important? Is loading the fonts (and probably rasterizing them to Bitmaps so they can be used) what needs time?

Many thanks in advance

Re: OpenGL initialization performance

Posted: Thu Nov 06, 2014 10:28 am
by 16469855
Yeray thanks for response. As Jens mentions the most interesting thing in enclosed project is that if we call InitWindow first time it took on debug mode 550-650ms but second time takes less than 20ms. Now we can use InitWindow on application startup and then all charts will appear much faster.

Re: OpenGL initialization performance

Posted: Thu Nov 06, 2014 11:23 am
by yeray
Hi,
jens.mertelmeyer wrote:
  • Thanks for showing us the TGLCanvas::InitWindow(..) command. That looks like pretty much what I was looking for
Paul wrote:Now we can use InitWindow on application startup and then all charts will appear much faster.
Great to hear that helped you!
jens.mertelmeyer wrote:
  • Can you elaborate on the font stuff? Why is the number of different fonts used important? Is loading the fonts (and probably rasterizing them to Bitmaps so they can be used) what needs time?
The first time a font is used in a TextOut call, OpenGL initializes it and takes its time for it. Then, using the same font in different TextOut calls is almost immediate.
I'm afraid I haven't found a way to initialize a Font apart, that would presumably allow you to move that initialization too.