Jump to content


Photo

Form creation performance slowdown with many NextGrid and NextDBGrid components


  • Please log in to reply
9 replies to this topic

#1 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 01 June 2017 - 04:17 PM

Greetings

 

While checking and optimizing one of my projects, I have stumbled on one weird behavior creating new forms at runtime. After creating each new form, forms initialization-creation time increases from 20 ms to even several hundred millisecond, couple people are reporting that form creation takes some several seconds, cant check those cases because I don't have access to those PC's.

And it all comes down to NextGrid. If form has one or two grids, creation time increase is negligible from none to few ms after 10 forms created. But, we have a form witch contains a tabcontrol with 14 tabsheets, each of those contain 1-4 NextGrids, in total around 22 mostly small and a few larger grids. smaller ones do contain atmost 10 columns, largest 2 grids contain no more than 20 columns.  

There where no issues with filling all those grids with data as I initially did suspect, there is single SQL call returning an XML from which all grids are then filled, request and filling takes constant 200-400 ms on create event.    

I did create a test project with two forms , copied all components from project's troubled form without any logic functions and database components and tested creation times.

Initially first form creates and shows in 550 ms, from which form show takes 40 ms, initialization time is around 510 ms, after each consecutive form is created and not freed,  initialization time increases by around 100 ms and more, for example:

-512 ms first form
-622 ms second form 
-778 ms ...
-903 ms ...
-1093 ms ...
 
if all 5 forms have been closed and freed, new forms creation time drops back to 530 ms. 
After deleting all grids and doing same test,  with little bit more than 300 other visual components left on the form (like labels,buttons, editboxes, comboboxes, timages and several other standard and Next components)
form initialization times are around 180-200 ms and shows at 220-300 ms and those times are constant even if there are created and left open more than 30 same forms.
 I only observed this problem using nextgrid and nextdbgrid components. 
On all windows versions ranged from XP to windows 10 programs behavior is about the same, only for some initialization takes longer for some shorter time spans.
Program originally  is written using Delphi XE2 and nextgrid verion 5.9.50 , did run test app using Delphi Berlin 10.1 update 2 too, With Berlin, creation times where slightly faster but not by much, few milliseconds. 
 
Is this normal or is there a reason why after creating each form it takes longer to create the form with nextgrid components? 
 
Another note, those users who reported really long times (even up to 20 seconds) did say that problem persists even after closing application, until you rebooting system, then it returns to normal behavior for 1-2 days described above and after that (if pc is left running without shutdown) forms create slower and slower and pc needs to be rebooted. There are no memory problems or memory leaks which i know and fastmm4 didn't report any, no viruses or other causes, other applications like excel or browsers work fine without noticeable changes. But I doubt that those cases are linked to this problem and cause might be somewhere else, but who knows. 
 
Attached File  formtest.rar   10.29KB   3 downloads
 
 
 
 


#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 01 June 2017 - 04:50 PM

Hi,

Thank you for the demo, I hope that I will find what may be the cause. It may take few days until I figure.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 08 June 2017 - 09:48 AM

Is there any progress in finding whats could be the cause for this ?



#4 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 09 June 2017 - 03:05 PM

Today I confirmed my suspicion that behind worst case times was indeed NextGrid. 

I did get access to an employees pc. He reported, that for him form creates in 4-5 seconds.

Did run this same formtest demo application and indeed form creation times are awful, even first form takes 4 sec to create not mentioning next form creation times increases. After restarting the machine, large delays did disappear. 

 

I really hope this problem can be solved soon, It's kinda awkward to tell users to restart their PC's every other day to solve the problem, while in every other way PC is working fine.

 

Maybe it has something to do with the way forms are created? Maybe I am doing it wrong or something?



#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 10 June 2017 - 01:07 AM

Hi,

It's a problem with memory leak as far I can see. I can't only figure when memory leak occur in your demo (using FastMM4) since on single grids there is no leak - but only in some combinations.

I'm trying to find which combination make leak.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#6 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 14 June 2017 - 04:45 PM

Greetings,

My knowledge about debugging Delphi is quite weak, Did try to debug and find the cause in a primitive way, don't ask... 

But didn't find anything, I suspect twincotrol in relation to nextgrid might have something to do with it, i duno.

only leak i might found is FSearchTimer in NxCustomGrid pas, I didnt find any code where it is being freed. 

 

While tiredly meddling with NextGrid code and forms I did find some hope. When putting that pagecontrol with all grids into a Tframe control and placing that frame on the form, those creation times got 3-5 times better, There is still some increase in creation times after each form was created, but its way way better and acceptable. It will take a while to rewrite some heavy forms and use frames in the original project and hopefully that will solve my headache for now. 

 

edit. Well in demo app it worked, in the project it didn't.



#7 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 16 June 2017 - 09:41 AM

hi,

Boki, I have a question, what does this code do in NxColumnDragBox.pas? 

I'ts been called twice per grid in TNxCustomGrid setting FDownDragArrow.ArrowKind := akDown; and akUp. 

SetWindowRgn(Handle, R, True) Call might be the one of the culprits, because commenting that line out, creation times improve a lot.

procedure TDragArrow.SetWindowShape;
var
   APoints: array [1 .. 8] of TPoint;
   R: HRGN;
begin
inherited;

case FArrowKind of
   akDown:
      begin
      APoints[1] := Point(5, 0);
      APoints[2] := Point(3, 0);
      APoints[3] := Point(3, 4);
      APoints[4] := Point(0, 4);
      APoints[5] := Point(4, 9);
      APoints[6] := Point(9, 4);
      APoints[7] := Point(6, 4);
      APoints[8] := Point(6, 0);
      end;
   akUp:
      begin
      APoints[1] := Point(-1, 5);
      APoints[2] := Point(4, -1);
      APoints[3] := Point(9, 5);
      APoints[4] := Point(6, 5);
      APoints[5] := Point(6, 9);
      APoints[6] := Point(3, 9);
      APoints[7] := Point(3, 4);
      APoints[8] := Point(0, 5);
      end;
end;
R := CreatePolygonRgn(APoints, 8, WINDING);
 SetWindowRgn(Handle, R, True);      //

end;


#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 16 June 2017 - 10:52 PM

Hm,

This are arrows for column-dragging. If you don't have moving columns you can comment this.

But I think that memory leak should be problem. Still trying to find where is a problem (sorry for delay).
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 LongBeard_Boldy

LongBeard_Boldy
  • Members
  • 11 posts

Posted 06 July 2017 - 09:56 AM

Hi,

you are right, memory leak is the problem. 

Did get burned few times trying to solve this, I guess leak was affecting some random functions or windows resources. 

Issue with SetWindowRgn being slow did disappear after next PC restart and didn't return back, i was eager and to hasty to accuse that function  :D .

To mitigate and reduce this problem I took different approach creating forms.

I created pool for those forms, new form is created and added to pool if pool is empty or there are no available forms in the pool.

After form is closed,  it's data is cleared, set to be available again and reused later on a new call.

This way that form is created only few times per session, rarely exceeding 5 open forms at the same time, reducing accumulating delay  and form call times to zero when reusing, making application lot more responsive.

 

 

 



#10 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 12 July 2017 - 03:25 PM

Good to hear it.

Leak is happening in only some situations/combinations and it's hard to isolate. If you use FastMM4 (or integrated in IDE) maybe you can catch it by accident and I will be able to fix it.

First thing I do is to check if there is some object non-released while testing.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users