TZAbstractDataSet too slow to iterate 7668 rows

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

TZAbstractDataSet too slow to iterate 7668 rows

Post by louis »

This code, with Delphi 2010 and FB 2.5.9, takes 11 seconds to complete:

Code: Select all

begin
  Cursore := Screen.Cursor;
  Screen.Cursor := crHourGlass;

  Result := 0;
  bmBookmark := ADataSet.GetBookmark;
  ADataSet.DisableControls;
  try
     ADataSet.First;
     while (not ADataSet.Eof) do
     begin
       if (ADataSet.FieldByName(AField).AsInteger >= Result) then
         Result := ADataSet.FieldByName(AField).AsInteger + 1;
       ADataSet.Next;
     end;
  finally
    ADataSet.GotoBookmark(bmBookmark);
    ADataSet.FreeBookmark(bmBookmark);
    ADataSet.EnableControls;
    Screen.Cursor := Cursore;
  end;
end;
How I can speed up?

Thanks
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by marsupilami »

You could try to see what happens when you use the Zeos 8.0 Beta. It also really depends on the data that is loaded into the dataset. It also could be a problem on the firebird side. If it is a real firebird server: Is processing time consumed by the Delphi application or by the firbird process?
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by louis »

marsupilami wrote: 23.04.2021, 10:47 You could try to see what happens when you use the Zeos 8.0 Beta.
At a moment I cant try with this version, :(
t also really depends on the data that is loaded into the dataset.
Data fields are:
Integer x 2
Smallint x 7
Char(29) x 2,
Char(4) x 1,
Char(2) x 1,
Varchar(480) x 1,
Varchar(10) x 1,
Varchar(60) x 1,
Numeric(7,4) x 1,
Numeric(18,4) x 4,
Float x 10,
Date x 1
It also could be a problem on the firebird side. If it is a real firebird server: Is processing time consumed by the Delphi application or by the firbird process?
Reading by Windows Task Manager: Delphi = 51% - Firebird = 0.8% during iteration.

Other Suggestions?

Thanks.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by marsupilami »

louis wrote: 23.04.2021, 12:03 Other Suggestions?
Indeed. Windows 64 Bits is slow when changing the cursor for 32 Bits applications. If you didn't disable the SQLHourglass cursor on the connection, try the following code:

Code: Select all

begin
  //Cursore := Screen.Cursor;
  //Screen.Cursor := crHourGlass;
  ADataSet.Connection.ShowSQLHourglass;

  Result := 0;
  bmBookmark := ADataSet.GetBookmark;
  ADataSet.DisableControls;
  try
     ADataSet.First;
     while (not ADataSet.Eof) do
     begin
       if (ADataSet.FieldByName(AField).AsInteger >= Result) then
         Result := ADataSet.FieldByName(AField).AsInteger + 1;
       ADataSet.Next;
     end;
  finally
    ADataSet.GotoBookmark(bmBookmark);
    ADataSet.FreeBookmark(bmBookmark);
    ADataSet.EnableControls;
    //Screen.Cursor := Cursore;
    ADataSet.Connection.HideSQLHourglass;    
  end;
end;
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by louis »

marsupilami wrote: 23.04.2021, 13:53If you didn't disable the SQLHourglass cursor on the connection, try the following code:
Takes more than 1 second longer :(

Thanks
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by miab3 »

Hi,

For me, it takes 5 seconds for 1 million iterations(without crHourGlass).
If dbgrid is connected, it takes 1 second, but the application starts 4 seconds (loads data to the cache and dbgrid).

procedure TForm1.Button1Click(Sender: TObject);
var
Res1:integer;
AField:string;
bmBookmark:TBookmark;
begin
AField:='TINT';
// Cursore := Screen.Cursor;
// Screen.Cursor := crHourGlass;

Res1 := 0;
bmBookmark := ADataSet.GetBookmark;
ADataSet.DisableControls;
try
ADataSet.First;
while (not ADataSet.Eof) do
begin
if (ADataSet.FieldByName(AField).AsInteger >= Res1) then
Res1 := ADataSet.FieldByName(AField).AsInteger + 1;
ADataSet.Next;
end;
finally
ADataSet.GotoBookmark(bmBookmark);
ADataSet.FreeBookmark(bmBookmark);
ADataSet.EnableControls;
// Screen.Cursor := Cursore;
end;
Edit1.Text:=IntToStr(Res1);
end;

Zeos8 svn7460; Firebird-2.5.9.27152-0_x64; Delphi 10.3.3-Win32 or Win64 on Win10-64

Michał
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by louis »

miab3 wrote: 23.04.2021, 17:24 For me, it takes 5 seconds for 1 million iterations(without crHourGlass)
Zeos8 svn7460; Firebird-2.5.9.27152-0_x64; Delphi 10.3.3-Win32 on Win10-64
:)

I have a problem to install Zeos8 because in this project I need to replace hundred of TFloatField to TBCDField but those TFloatField often have a Validate function combined.
I don't know how to replace those TFloatFields without risking to introduce some bugs dooing to losing some functions.

Any suggestion?

Thanks
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by marsupilami »

Usually I would use find and replace in the dfm files to just change the type information.
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by louis »

marsupilami wrote: 24.04.2021, 08:30 Usually I would use find and replace in the dfm files to just change the type information.
Do you mean:
1) view as text
2) search and replace?

Zeos8 is usable in production?

Thanks
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by aehimself »

louis wrote: 24.04.2021, 11:33Zeos8 is usable in production?
Absolutely. I even used it in production when it was still called 7.3. There were no deal-breakers, only some minor inconveniences - pretty easy to work around.

For SQLite, MySQL, MSSQL (FreeTDS) and Oracle, that is. I have no experience with the other protocols.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by marsupilami »

louis wrote: 24.04.2021, 11:33 Do you mean:
1) view as text
2) search and replace?
More or less - yes. I am storing my DFMs as text for ages now. So I can edit them with any editor and also get the ability to see changes in SVN.

Honestly - I wonder what happens on your computer. Usually I would suggest to try a profiler and see where time is spent. Some profilers I have found for now: I do have some (ancient) experience on GpProfile. But maybe one of the others is better for your problem.
DPStano
Junior Boarder
Junior Boarder
Posts: 39
Joined: 16.05.2016, 09:21

Re: TZAbstractDataSet too slow to iterate 7668 rows

Post by DPStano »

if your dataset is TZquery you can iterate over DbcResultSet, s/t like

Code: Select all

    
    with (DataSet as TZQuery).DbcResultSet do
    begin
      BeforeFirst;
      while Next do
      begin
	 GetIntByName('')
      end;
    end;
Post Reply