Recent

Author Topic: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4  (Read 3700 times)

Pi

  • Jr. Member
  • **
  • Posts: 68
I have a Lazarus program that I wrote in Lazarus version 1.4.4, on a Windows 10 machine that has 96 GB RAM (it used to have more) and an Intel i7-6850K processor.
On that PC whenever I clicked on an option that loaded a new form with the new form's name and showmodal (usually by using a control character shortcut) it seemed to almost always load the new form instantaneously.
The only thing that happens immediately after the form is loaded (in the formshow event) is it calls the clear option to clear the contents of a memo on the new form.

On my new PC (with Lazarus 2.2, Windows 10, 256 GB RAM with a faster processor - AMD 3960X) when the program initially runs I can select the new form and it seems to load immediately. If I then use an option on the new form that does do a lot of processing of records (using read command to read lots of records from a file, then maybe updating records or adding new ones), and that form then closes and the processing has finished (I know the processing has finished as I've added a showmessage on the  original form's calling procedure after it has, eg. after it may have updated a listbox with new info), if I then select the option to open the new form again or use the control shortcut to it (eg. control G), it can take seconds to open the new form (eg. about 6 to 8 secs) - even though the only thing happening when the new form shows is that it clears a memo's text on it (ie. that's before I've selected any button on the new form again to do any further processing). I don't know if the duration is dependent on the length of the text that was in the memo that is getting cleared.

Why does it take so long on the new machine with the newer version of Lazarus to open the new form at that time (when the processing that happened before trying to open it had finished) and is there anything I can do to make it faster (like it was on the old pc with the old lazarus)?

Is it anything to do with compiler debug info (it's set to use "Dwarf2 -gw2" in the newer Lazarus - the Lazarus 1.4.4 used "automatic (-g)" in the "Type of debug" option.
 (note: if I change the debug option to use "automatic (-g)" in the Lazarus 2.2 on the new PC like it was originally I get a message saying "This project does not write debug info in dwarf format" and giving 3 debug options or cancel so I assume it requires writing debug info in one of those 3 formats if you want some debug info written).

Is it anything to do with having more RAM in the new PC?
Or is it that the new Lazarus is a lot slower at clearing memos than the Lazarus 1.4.4) - depending on the amount of text in it?
« Last Edit: January 12, 2022, 08:58:00 pm by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

dseligo

  • Hero Member
  • *****
  • Posts: 613
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #1 on: January 12, 2022, 10:31:25 pm »
Sometimes adding more RAM helps  :)

If you suspect clearing of memo to be cause of this, why don't you test it?

You could do something like this:
Code: Pascal  [Select][+][-]
  1. var t: TDateTime;
  2. ...
  3. t := Now;
  4. Memo1.Lines.Clear;
  5. ShowMessage(FormatDateTime('nn:ss.zzz', Now - t));

If that is the cause then you can try to solve it like that:
Code: Pascal  [Select][+][-]
  1. Memo1.Lines.BeginUpdate;
  2. Memo1.Lines.Clear;
  3. Memo1.Lines.EndUpdate;

Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #2 on: January 13, 2022, 12:04:07 am »
Thanks a lot for both of the replies. I tried testing with the different codes. Originally I was using the memo_name.clear;
So I tried running it with the same stuff pasted into the memo and with that timer in each (timing the clearing of the memo) and also timing the appearance of the new form (using a watch) after pressing Ctrl G.

The 1st time into the new form (when the memo is already empty) with memo_name.clear shows time taken to clear the memo as 00:00.000 and is about immediately loaded.
After pressing the button to process records and that finishing and the form closing and other processing finishing:

The 2nd time into the new form (when the memo had text in the memo) still with the FormShow with memo_name.clear, shows the time taken to clear the memo as either 00:00.004 or 00:00.005 (and takes about 15 secs for the form to appear).
--
The 1st time into the new form (when the memo is already empty) with beginupdate, lines.clear, endupdate, showed 00:00.001 as the time taken for clearing the memo.
The 2nd time into the new form (when the memo had text into the memo) with beginupdate, lines.clear and endupdate, showed 00:00.002 as the time taken for clearing the memo and the form took about 13 secs to appear).
--
Using memo.text:='';

The 1st time into the new form (when the memo was already empty):  shows 00:00.000 as the time taken to clear the memo.
The 2nd time into the new form (when it had text in the memo before clearing it): shows 0:00.005 as the time taken to clear the memo and took about 13 secs for the form to appear.

So if my stopping of the stopwatch on my watch is right, those 2 seem to have reduced the time taken for the new form to appear the 2nd time by about 2 secs,
but still taking around 13 secs is quite a long time.

As of these tests for this post the debug option in the project options is set to "Dwarf with sets (-gw godwarfsets)" - I don't know if that makes any difference.

If the end figure in the time taken for the clearing of the memo is showing under a second in each that's probably meaning it can't really be the memo clearing that's the main issue (even though that's the only thing that happens in the FormShow event of the new form (apart from the new timer code to time it and display the time taken). But the first time of loading the new form (when the memo in it was already empty and before we've pressed any buttons later in that new form to process lots of records) was when it loads it instantly.

Could it be anything to do with the different debug options?
Or could past processing not have really stopped even though it's past the end of it and shown that it has with a showmessage saying it has (ie. if Lazarus does something in the background)?
Could Lazarus be doing it's own processing for some other reason (eg. garbage collection? or flushing some file buffers - even though previous processing should have stopped since it showed a message I put in that said that it had finished in the previous procedure?)?

I've checked and it definitely isn't doing anything much before the call to open the new form (when the past processing should already have been stopped).

ie. menu option to call the new form at the start just:

Code: Pascal  [Select][+][-]
  1. added_or_updated:=false; // sets a global variable
  2. frm_the_new_form_name.showmodal();
  3. showmessage('after showmodal');  // so never gets here until after the new form has
  4.                                  // been closed, so anything after this isn't what's
  5.                                  // causing the slowdown.

----
And in the new form that gets called (after selecting the option or pressing Control G),
the FormCreate procedure is empty.
and the FormShow just has the timer code and display and the memo clearing.

eg.

Code: Pascal  [Select][+][-]
  1. var t: tdatetime;
  2. begin
  3.  
  4.   t:=now;
  5.  
  6.  //  the_memo.clear;
  7.  
  8. // bits commented out so I could try the different ways of clearing it
  9.  {   the_memo.Lines.BeginUpdate;
  10.     the_memo.Lines.Clear;
  11.     the_memo.Lines.EndUpdate;
  12.   }
  13.  
  14.   the_memo.text:='';
  15.  
  16.   ShowMessage(FormatDateTime('nn:ss.zzz', Now - t));    
  17.  
  18. end;

[Edited to add code tags; please read How to use the Forum.]

Edited to add the timings for
Code: Pascal  [Select][+][-]
  1. the_memo.lines.clear
on its own (without the BeginUpdate and EndUpdate)
---
With the_memo.lines.clear (without beginupdate and endupdate);

1st time into new form: shows 00:00.000 as time taken to clear the memo. The new form appeared immediately after pressing Ctrl+G to show it.
2nd time into new form (when there had been something in the memo and past processing should have stopped): shows 00:00.002 as the time taken to clear the memo and the form appeared about 13 secs after pressing Ctrl+G to display it.
« Last Edit: January 13, 2022, 12:41:48 am by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7970
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #3 on: January 13, 2022, 12:32:24 am »
The debug info itself ( "Dwarf with sets (-gw godwarfsets)" or other) will not change the timing.
But => run your code outside the IDE. To make sure the debugger is not interfering.

Also, what else is on your form?

If you prevent text from being added to your form (during the first run), does the 2nd form.show go better?

What happens if instead you do not clear the lines?

If I understand correct, then you run "memo.Lines.Clear;" within the "OnFormShow" ?
What happens if you clear the lines before calling "form.show" or "form.showModal"?

How many lines are we talking about? 1000? 10000? 100k? 1M?

Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #4 on: January 13, 2022, 01:18:16 am »
On the new form (that gets called after Ctrl+G is pressed or the main menu option for it is selected), the only other things on it apart from the memo that we've been talking about is:

7 labels
6 edit boxes and 1 other memo (that doesn't get much text added to it).
2 buttons (one to process the memo text being discussed and the other button to cancel (close the form)

The edit boxes and the other memo only get filled in after pressing a button on that new form to process the contents of the memo that's been discussed (about the clearing of it).
----
If there is no text added to the memo then there can be no processing of the text in it (after pressing a button the form) so yes it does make it load faster (immediately).

I think it is because of the amount of text in the memo (not the processing of the records) because when I just press the cancel button when it has that amount of text in it (so no records are read from a file again) it still takes about 10-11 secs for it to show the form after pressing Ctrl+G.

The amount of lines in the memo that is being discussed (the memo that gets processed) is currently 29,333 and the length of the memo.text is 619,618 (it depends what I paste into it but that's the amount that there was on the 2nd load of the form for the timings shown above). The width of the memo is 150 (so quite narrow - I could reduce the amount of lines probably by increasing that if that helped - but the procedure that reads the memo text doesn't look at the lines, only the memo.text in it.

Yes I'll check to see what difference there is running just the .exe file of the program out side of the IDE tomorrow morning thanks.
« Last Edit: January 13, 2022, 01:20:19 am by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1983
  • Former Delphi 1-7, 10.2 user
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #5 on: January 13, 2022, 01:32:47 am »
What happens if you clear the memo when you close the form instead of clearing the memo when you open the form?
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7970
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #6 on: January 13, 2022, 01:57:56 am »
ok, I did a test here.

Dropped a memo on a form (2nd form, so form1 can reopen the form, once I closed it).
Copy and pasted 40k lines. => all fast (paste takes maybe 1 second).

But, I had the memo wide enough for each line to fit without wrapping.
And, if I resize the memo (alclient, resize form), yes well that takes time / maybe 3 or 4 seconds).

However, if I put "Form2.Width := 200;"  into the OnFormShow => that takes about 10 secs (if I do it before the lines are cleared).

avra

  • Hero Member
  • *****
  • Posts: 2344
    • Additional info
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #7 on: January 13, 2022, 08:25:36 am »
Did you test Lazarus 1.4.4 executable from old machine on your new machine?
Did you test Lazarus 2.2 executable from new machine on your old machine?
How do they behave?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #8 on: January 13, 2022, 10:53:56 am »
Thanks a lot everyone.  :)

It seems the main issue was the width of the memo and the amount of text causing lots of word wrapping that takes it a long time (eg. about 13 secs) when the new form loads with it.
I could increase the memo width further and that should help since it should cause less word wraps, and be easier to check visually if needed (though I rarely need to check it that way).

For now I've turned off word wrapping as the word wraps don't matter to the procedure that processes the memo text. That's made the number of memo lines for that same text go from 29,333 to just 730.
That's made it load about instantly each time when it has that amount of text and has speeded up the pasting into the memo (it now does it about instantly). And clearing it with mem_name.clear takes 00:00.004 or 00:00.005.

I've also added the memo clear in the form's OnClose event. I've tried that with the word wrap turned on and that does speed up the re-loading of the new form after it had that text pasted into into previously thanks for the suggestion. Though with word wrap turned off the difference isn't as much (but it will help if I ever need to turn it back on or have it turned on in some other app). I think I'll keep word wrap off for now as that speeds up the pasting into the memo and it doesn't affect the processing of the memo text by my procedure.

I'll try checking the old and new machine with the Lazarus 1.4.4 and Lazarus 2.2 executables later to see what the differences are with this. Thanks.
« Last Edit: January 13, 2022, 11:13:07 am by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

_Bernd

  • New Member
  • *
  • Posts: 21
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #9 on: January 13, 2022, 12:03:05 pm »
Hello,

maybe this also has something to do with the fpc version. Lazarus 1.4.4 was probably still based on fpc 2.x. I had noticed something similar during the transition from Lazarus 1.4.4 to 1.6:

https://www.mail-archive.com/lazarus@lists.lazarus-ide.org/msg01461.html

But I can't remember how that turned out.

Regards, Bernd.

pcurtis

  • Hero Member
  • *****
  • Posts: 939
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #10 on: January 13, 2022, 12:13:22 pm »
Try to run without debugging?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #11 on: January 13, 2022, 07:51:43 pm »
Did you test Lazarus 1.4.4 executable from old machine on your new machine?
Did you test Lazarus 2.2 executable from new machine on your old machine?
How do they behave?
I've just done some tests.

On the old Win 10 Pc (i7-6850K) with Lazarus 1.4.4 executable (that has the memo with wordwrap on),
with the same text as previously tested, it takes 5 secs to paste it into the memo, but unlike with the other Lazarus version, loading the new form and clearing the memo as it loads is always instantaneous for each form load.

On the old win 10 pc, with the Lazarus 2.2 executable (that has the memo with wordwrap on), with the same text,
the first time into the new form is instantaneous. It also takes 5 secs to paste the text into the memo.
The 2nd time into the new form takes 11 secs for it to get to the memo cleared timer button (so a lot longer than with Lazarus 1.4.4).
----
Testing the Lazarus 1.4.4 executable on new Win 10 PC (3960X).

On the new win 10 pc, with Laz 1.4.4, with the memo with wordwrap on and using the same text as other tests.
1st time in the new form is instant. Pasting the text into the memo took 4 secs.
Each new load of the new form (where it clears the memo) is also instant.
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #12 on: January 13, 2022, 08:27:48 pm »
Hello,

maybe this also has something to do with the fpc version. Lazarus 1.4.4 was probably still based on fpc 2.x. I had noticed something similar during the transition from Lazarus 1.4.4 to 1.6:
Thanks. Yes the Free Pascal version was 2.6.4 in Lazarus 1.4.4 (that's what it shows on my old pc).
That helps show there's an issue with the memos slowing down (at least with wordwrap which is enabled by default). Hopefully it will get fixed (though it seems it's been slower in the newer versions since about November 2016).

Though if I keep wordwrap off for my current app it should be okay, but it will likely still be an big problem with those that need to use memos with wordwrap when there's quite a lot of text (unless if there's something other than memo that could be used - one person in that thread is suggesting SynEdit - though I've not used that and it seems more complex and according to a post wordwrapping in that seems to have issues or is more difficult - there's not just a property for it like tmemo).

Quote
Try to run without debugging?
I tested it with just clicking on the compiled .exe files (to give the results shown in my tests with the old vs new pc and old vs new Lazarus shown above.
Or if you mean it's compiled debug info into that .exe I could try changing the compiler options. Though with wordwrap off it works much faster/about instantly so for this project I can continue with wordwrap off.
But the slowdown of memos - with wordwrap on I think - seems to have been confirmed eg. with the thread linked above.
« Last Edit: January 13, 2022, 08:35:55 pm by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7970
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #13 on: January 13, 2022, 10:00:50 pm »
I don't think its the fpc version.

I would say it's likely that in 1.4.4 the wordwrap did not get triggered at this point.
Since then several wordwrap related bugs where fixed. Well possible that one of them made it necessary to change when the wrapping happens.

In the end, if you have a Memo with wordwarp enabled, and several 10k lines in it, you have to expect that at some time, to work needs to be done.

As to whether it could (or even should?) be avoided in your particular code flow, well that can't be told without knowing your code. And without having the time to do so. Comparison with 1.4.4 does not help here....



Pi

  • Jr. Member
  • **
  • Posts: 68
Re: Lazarus 2.2 seems to be a lot slower loading a form than Lazarus 1.4.4
« Reply #14 on: January 14, 2022, 12:13:24 pm »
In the end, if you have a Memo with wordwarp enabled, and several 10k lines in it, you have to expect that at some time, to work needs to be done.
Thanks for your reply. In my current project I can just leave wordwrap off in that memo as it doesn't really need it.

Though for it needing to do the work at some time, if it takes about 5 secs to paste the text into the memo box, and I assume it's doing the wordwrapping as it's being done (since pasting it with wordrwap off is instant), it seems unusual that it takes about 10 secs to load the form again and do the wordwrapping when it only took 5 secs to do it when it was pasted in. Also if it does the wordwrapping as soon as soon as the text is pasted in, and then the form is closed, maybe it could save the wordwrapping info somewhere to save having to do it again when the form is re-opened (though maybe it's releasing the memory when the form is closed, which may be okay but still I don't see why it's about double the time to wordwrap it on form re-loading than when it's pasted into the memo).
« Last Edit: January 14, 2022, 12:16:44 pm by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

 

TinyPortal © 2005-2018