Very slow Hyperlink creation (v5.10.26)
Posted: Thu Jun 27, 2013 1:14 pm
Hello!
Writing a large number (180.000 rows) of hyperlinks into an XLSX file took me more than 6 minutes.
I profiled the XLS ReadWrite component and it seems that there are two methods which are responsible for this behaviour:
1.
function TOPCItem.MakeId: AxUCString;
var
n: integer;
begin
n := FChilds.Count + 1;
Result := 'rId' + IntToStr(n);
while getchildindex(fchilds, result) >= 0 do begin
Inc(n);
Result := 'rId' + IntToStr(n);
end;
end;
The 'while' loop seems not to be necessary since the code in the loop seems never to be used and
this loop is very time consuming.
2.
procedure TXLSWorksheet.SetAsHyperlink(ACol, ARow: integer; const Value: AxUCString);
var
HLink: TXLSHyperlink;
begin
HLink := FHyperlinks.Find(ACol,ARow);
if HLink = Nil then
HLink := FHyperlinks.Add;
if Copy(Lowercase(Value),1,3) = 'www' then
// Hyperlinks in Excel 2007 must start with http://
HLink.Address := 'http://' + Value
else
HLink.Address := Value;
HLink.Col1 := ACol;
HLink.Col2 := ACol;
HLink.Row1 := ARow;
HLink.Row2 := ARow;
end;
The first line in this procedure seems not to be necessary if you write the hyperlinks to a new file and increase the rows
and columns in a loop since HLink always returns nil for me in this case (the hyperlinks.findoperation extremley slows down the
file creation)
Another issue: writing more than ~65000 rows as hyperlinks seems to create corrupted xlsx files.
When I removed both code parts from the methods, the hyperlink creation was really fast.
Could you please take a look at the code for the hyperlink creation and check if there are some possible optimizations.
Thank you.
Best regards.
Writing a large number (180.000 rows) of hyperlinks into an XLSX file took me more than 6 minutes.
I profiled the XLS ReadWrite component and it seems that there are two methods which are responsible for this behaviour:
1.
function TOPCItem.MakeId: AxUCString;
var
n: integer;
begin
n := FChilds.Count + 1;
Result := 'rId' + IntToStr(n);
while getchildindex(fchilds, result) >= 0 do begin
Inc(n);
Result := 'rId' + IntToStr(n);
end;
end;
The 'while' loop seems not to be necessary since the code in the loop seems never to be used and
this loop is very time consuming.
2.
procedure TXLSWorksheet.SetAsHyperlink(ACol, ARow: integer; const Value: AxUCString);
var
HLink: TXLSHyperlink;
begin
HLink := FHyperlinks.Find(ACol,ARow);
if HLink = Nil then
HLink := FHyperlinks.Add;
if Copy(Lowercase(Value),1,3) = 'www' then
// Hyperlinks in Excel 2007 must start with http://
HLink.Address := 'http://' + Value
else
HLink.Address := Value;
HLink.Col1 := ACol;
HLink.Col2 := ACol;
HLink.Row1 := ARow;
HLink.Row2 := ARow;
end;
The first line in this procedure seems not to be necessary if you write the hyperlinks to a new file and increase the rows
and columns in a loop since HLink always returns nil for me in this case (the hyperlinks.findoperation extremley slows down the
file creation)
Another issue: writing more than ~65000 rows as hyperlinks seems to create corrupted xlsx files.
When I removed both code parts from the methods, the hyperlink creation was really fast.
Could you please take a look at the code for the hyperlink creation and check if there are some possible optimizations.
Thank you.
Best regards.