Recent

Author Topic: Windows with many controls paint slowly on Windows  (Read 10892 times)

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Windows with many controls paint slowly on Windows
« on: November 29, 2017, 08:50:38 am »
Greetings everyone,

Hopefully this is the correct forum to post under.  Please forgive me if it's not.

My limited time I've had to explore Lazarus and make a few test programs has been enjoyable. 

While I've personally been using Lazarus on Linux, I have a VB6 app I'd like to migrate over for my customers on Windows.  Some of the screens on this app have 100+ controls on them (yes, not good practice but customer-dictated).  The VB6 runtime paints these windows completely and quickly while the executable compiled on Lazarus / Windows paints a bit slowly in comparison.  Here are three frames from a video capture of the Lazarus / Windows being restored from being minimized (providing a link because the image is somewhat large):

Animated GIF showing painting progression

As you can see, the painting takes a while, compared to VB6 and Java running on the same machine with 100+ similar controls.  VB6 and Java apps with windows that contain the same amount of controls appear with no noticeable delay.  The only thing that paints slower is a .Net app with the same amount of controls -- it's painfully slow when painting -- much slower than Free Pascal / LCL.

The executable I compiled was set with debug options off.  I tried explicitly disabling and enabling double-buffering for the form, but no difference was seen.  There is no code behind the Free Pascal window shown above, just the controls.

I'm running all of these test apps on a Windows 7 virtual machine (VirtualBox) and have also verified that everything behaves the same on Windows 7 running on 'bare metal'.  I have a decent AMD video card, my system has an eight-core processor topping out at 4 GHz and 16 GB of RAM, with the VM given 4 GB of RAM, so no resource starvation.

Is there anything I can do to speed up Free Pascal / LCL's drawing on Windows?  On Linux / X11, the same form with hundreds of controls shows almost immediately with no slow painting.

Thank you!  :D
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

Handoko

  • Hero Member
  • *****
  • Posts: 5436
  • My goal: build my own game engine using Lazarus
Re: Windows with many controls paint slowly on Windows
« Reply #1 on: November 29, 2017, 09:38:29 am »
Can you please provide us the compile-able source code for us to inspect. Here has many seniors who will be happy to help you, I believe your problem will be solved.

If you do not wish to publish the project, you can write a demo that showing that issue. Compress all the necessaries files except the binary, *.bak and lib folder and send the zip file to this forum.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: Windows with many controls paint slowly on Windows
« Reply #2 on: November 29, 2017, 10:47:10 am »
I've had the same issue when trying to develop a minesweeper game :) ~1000 controls take several seconds to create/init. https://github.com/eugeneloza/Metar-Sweeper
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

balazsszekely

  • Guest
Re: Windows with many controls paint slowly on Windows
« Reply #3 on: November 29, 2017, 11:08:46 am »
Catch WMEnterSizeMove, WMExitSizeMove messages then disable window update between them.

avra

  • Hero Member
  • *****
  • Posts: 2546
    • Additional info
Re: Windows with many controls paint slowly on Windows
« Reply #4 on: November 29, 2017, 11:17:36 am »
Is there anything I can do to speed up Free Pascal / LCL's drawing on Windows?  On Linux / X11, the same form with hundreds of controls shows almost immediately with no slow painting.
Maybe you can find an inspiration here:
https://stackoverflow.com/questions/3792217/how-can-i-disable-screen-update-which-updating-a-lot-of-controls
http://www.festra.com/eng/tip-beginupdate.htm
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #5 on: November 29, 2017, 05:53:46 pm »
Thank you everyone for your response!  I was very pleased to see so many replies!  I will try the suggestions and let you know! :D

@Handoko, as noted in my original post, there is no code, just the one form with the many controls.  It actually *is* a test project.  :)
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

wp

  • Hero Member
  • *****
  • Posts: 12859
Re: Windows with many controls paint slowly on Windows
« Reply #6 on: November 29, 2017, 06:16:40 pm »
Quote
It actually *is* a test project.
Then why don't you upload it? Such a simple project would just be perfect, and we all would know exactly what you are talking about...

In the mean time I wrote my own project for this issue, just straightforward, no tricks. Well - maybe there is some sluggish reaction when the form loads, but I would not complain about it seriously. Is your program behaving like mine?

How do you paint the background image? Without the background image the labels and edits appear immediately.
« Last Edit: November 29, 2017, 06:18:26 pm by wp »

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #7 on: November 29, 2017, 07:06:27 pm »
Then why don't you upload it? Such a simple project would just be perfect, and we all would know exactly what you are talking about...

Because it's top-secret...must make you sign an NDA :P  Just kidding.  I will do that as soon as I can...
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #8 on: November 29, 2017, 07:25:36 pm »
Then why don't you upload it? Such a simple project would just be perfect, and we all would know exactly what you are talking about...

Here it is.  Thanks for your patience! :)
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1529
    • Lebeau Software
Re: Windows with many controls paint slowly on Windows
« Reply #9 on: November 29, 2017, 07:29:05 pm »
I've had the same issue when trying to develop a minesweeper game :) ~1000 controls take several seconds to create/init. https://github.com/eugeneloza/Metar-Sweeper

That is because you are using TPanel (a *windowed* control) for your boxes.  Each panel takes up an HWND handle, and thus has system resources behind it.  Try switching to TImage instead (a *graphical* control) and you will likely see a HUGH improvement in performance.  The fewer *windowed* controls you have, the faster things can create and paint.  This is why high-performance apps, like web browsers, games, etc don't use a lot of windowed controls to begin with.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

wp

  • Hero Member
  • *****
  • Posts: 12859
Re: Windows with many controls paint slowly on Windows
« Reply #10 on: November 29, 2017, 07:36:22 pm »
Here it is. 
It this slow? The form comes up immediately.

Where is the background image? What exactly are you doing when you see the speed issue?
« Last Edit: November 29, 2017, 07:43:21 pm by wp »

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #11 on: November 29, 2017, 07:50:24 pm »
That is because you are using TPanel (a *windowed* control) for your boxes.  Each panel takes up an HWND handle, and thus has system resources behind it.

Oh yes, this is so true.  When I first got into Win API programming using C, I tried writing up a GUI form editor using *real* controls instead of drawn copies of them. :P  I exhausted my HWND handles quickly and found it was very slow.  Drawing the controls instead of making instances of them made a really positive difference.
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #12 on: November 29, 2017, 07:53:24 pm »
It this slow? The form comes up immediately.

Where is the background image? What exactly are you doing when you see the speed issue?

I am not using a background image.  The form paints slow on my hardware, both virtualized and non-virtualized, as shown in the animated GIF above.  I can provide the actual video, if that would be helpful?
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

willbprog9933

  • Jr. Member
  • **
  • Posts: 93
  • Big guy, tiny brain :P
    • BrainOut!
Re: Windows with many controls paint slowly on Windows
« Reply #13 on: November 29, 2017, 08:09:21 pm »
Hi again,

Here is the video capture that I derived the animated GIF from.  In the video, I restore and minimize the form from the Free Pascal demo project I made a few times, and you can see the slow drawing.  Later, I restore and minimize a demo Java app with the same amount of controls, which shows absolutely zero drawing latency.

Video capture of slow form drawing
macOS, Linux, FreeBSD and sometimes OpenIndiana.

Blessed, loved and forgiven! :D

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1529
    • Lebeau Software
Re: Windows with many controls paint slowly on Windows
« Reply #14 on: November 29, 2017, 08:25:19 pm »
Oh yes, this is so true.  When I first got into Win API programming using C, I tried writing up a GUI form editor using *real* controls instead of drawn copies of them. :P  I exhausted my HWND handles quickly and found it was very slow.  Drawing the controls instead of making instances of them made a really positive difference.

I did something similar once.  I had an old app that used hundreds of colored TPanel controls as status lights.  UI updates were a bit slow and resource-intensive.  So I wrote a custom TGraphicControl component (*) to display the status lights (and since the lights were being displayed in groups, I made the control able to display a whole group at a time).  I was able to replace those hundreds of Panels with a dozen graphic controls, and the UI was vastly faster and its resource usage dropped like 45%!

(* and then I made a screensaver of flashing lights and patterns using just one instance of that graphic control :D )
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018