TAChart performance - adding new points to line chart is getting slower with more values in chart
Original Reporter info from Mantis: drevo10
-
Reporter name:
Original Reporter info from Mantis: drevo10
- Reporter name:
Description:
When drawing chart containing thousands values adding one more value gets longer and longer.
The issue is the current algorithm of function Add calling universal AddXY function.
The AddXY function currently walks through all the values within series to the end in order to find right place for new XY point.
My patch checks whether it is last value or not at the beginning. If so, the value is added to the end without walking through each point within series.
Just for your imagination putting the patch speeds up loading of the chart containing 30000 points from cca minute to few seconds on my recent dual core laptop.
Additional information:
Here is commented original AddXY function followed by my customized function.
(*function TChartSeries.AddXY(X, Y: Double; XLabel: String; Color: TColor) : Longint;
var
coordn: PChartCoord;
i: integer;
begin
//save the coord and color
New(Coordn);
Coordn^.x := X;
Coordn^.y := Y;
Coordn^.Color := Color;
Coordn^.Text := XLabel;
//add in order or at end
i := 0;
while (i < FCoordList.Count) and (PChartCoord(FCoordList.Items[i])^.x <= X) do inc(i);
if i = FCoordList.Count then FCoordList.Add(Coordn)
else FCoordList.Insert(I+1, Coordn);
// FCoordList.Add(Coord);
result := FCoordList.IndexOf( Coordn );
end;*)
function TChartSeries.AddXY(X, Y: Double; XLabel: String; Color: TColor) : Longint;
var
coordn: PChartCoord;
i: integer;
begin
//save the coord and color
New(Coordn);
Coordn^.x := X;
Coordn^.y := Y;
Coordn^.Color := Color;
Coordn^.Text := XLabel;
//add in order or at end
if FCoordList.Count = 0 then
FCoordList.Add(Coordn)
else
if X > PChartCoord(FCoordList.Items[ FCoordList.Count-1 ])^.x then
FCoordList.Add(Coordn)
else begin
i := 0;
while (i < FCoordList.Count) and (PChartCoord(FCoordList.Items[i])^.x <= X) do inc(i);
(* if i = FCoordList.Count then FCoordList.Add(Coordn)
else *) FCoordList.Insert(I+1, Coordn);
end;
// FCoordList.Add(Coordn);
result := FCoordList.IndexOf( Coordn );
end;
Mantis conversion info:
- Mantis ID: 11723
- Version: 0.9.24
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 17504 (#0d6bfec7)
- Monitored by: » drevo10 (drevo10)