Calling Form.Fields in a loop very slow

Hello,

I have noticed a performance problem when calling the Form.Fields property on the attached PDF with a large number of fields. input.pdf (3.3 MB)

The following code takes extremely long time - about 2 seconds per property, over an hour to run:

var pdf = new Aspose.Pdf.Document("input.pdf");

for (int i = 0; i < pdf.Form.Fields.Length; i++) // over an hour to exit loop
{
    var field = pdf.Form.Fields[i];
    Console.WriteLine(field.PartialName + ": " + field.Value);
}

Luckily I did discover a workaround. The following code completes in 7 seconds:

var pdf = new Aspose.Pdf.Document("input.pdf");
var fields = pdf.Form.Fields; // cache Form.Fields property in local variable

for (int i = 0; i < fields.Length; i++) // 7 seconds to exit loop
{
    var field = fields[i];
    Console.WriteLine(field.PartialName + ": " + field.Value);
}

I think that each call to Form.Fields is re-instantiating the property, which makes example 1 take very long time. In example 2, this is avoided by manually caching Form.Fields in a local variable.

While there is a workaround, it might take a long time to check all code and sometimes might be missed. And also this might affect other users. So I report it as a bug that could be investigated. If Aspose.PDF could cache the Forms.Fields property I think that would solve this.

@ast3

Thanks for contacting support.

We were able to notice the similar behavior which you have mentioned. Therefore, we have logged an enhancement request as PDFNET-49495 in our issue tracking system. We will surely investigate the feasibility of your requirements and let you know as soon as the logged ticket is resolved. Please give us some time.

We apologize for the inconvenience.