Will there be any difference in report generation time if Word template coming from SharePoint Instead of current directory

Will there be any difference in report generation time if Word template coming from SharePoint Instead of current directory

Note: If we will use custom implementation to get the template from SharePoint not using Aspose.Words for SharePoint

@Gauravgarg01 The report generation time does not depend on the source from where the source document is loaded. The different in time can be caused only by the time required for loading the file from external storage, but this is out of Aspose.Words scope.

@alexey.noskov

But we have noted the time taken by build report is more if we are using the template coming from SharePoint

Same SharePoint template taking more time to build the report, the time taken by the template in current directory

@Gauravgarg01 Do you use code like the following?

Stream inputDocument = //... get document stream from the file or from SharePoint

Document doc = new Document(inputDocument);

// Generate the report.
// .......

// Save the output
doc.Save(@"C:\Temp\out.docx");

if the input stream loaded from file or from SharePoint are binary the same, there should not be any difference in the time of document processing using Aspose.Words.

@alexey.noskov

We are using memory stream

@Gauravgarg01 If the document in the stream is the same as loaded from file, then the report generation time should be the same.

@alexey.noskov
Just to clearify the stream is not same but the same template is placed on sharepoint and local. Below line is taking more time if pass Stream created using SharePoint template and taking less time for local template

reportingEngine.BuildReport(templateDocumentStream, documentJsonData, “d”);

Please help on performance part as it’s critical for us to found the differerance
Please help if there is any other ways as well to improve the performance

@alexey.noskov Please help here

Just to clearify the stream is not same but the same template is placed on sharepoint and local. Below line is taking more time if pass Stream created using SharePoint template and taking less time for local template

reportingEngine.BuildReport(templateDocumentStream, documentJsonData, “d”);

Please help on performance part as it’s critical for us to found the differerance
Please help if there is any other ways as well to improve the performance
We are just calculating the BuildReport time

@Gauravgarg01 Could you please run the following code with your template loaded from file and from SharePoint and sure results here:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Load the file into a stream.
Stream docStream = File.OpenRead(@"C:\Temp\in.docx");
Console.WriteLine($"Stream load time: {stopwatch.ElapsedMilliseconds}ms");

stopwatch.Restart();
// Open document from stream
Document doc = new Document(docStream);
Console.WriteLine($"Document load time: {stopwatch.ElapsedMilliseconds}ms");

stopwatch.Restart();
// But the report
ReportingEngine engine= new ReportingEngine();
engine.BuildReport(doc, documentJsonData, "d");
Console.WriteLine($"Report generation time: {stopwatch.ElapsedMilliseconds}ms");

stopwatch.Restart();
// Save the output.
doc.Save(@"C:\Temp\out.docx");
Console.WriteLine($"Document save time: {stopwatch.ElapsedMilliseconds}ms");

Also, please attach your template and sample data source that will allow us to reproduce the problem.

sample.docx (36.8 KB)
SharePoint template is stored on Sharepoint web (it’s authenticated or secure site).
The time to read stream from sharepoint is not a problem.

Problem is with BuildReport time or Report Generation time.

NOTE Same template is on sharepoint we and same template is on Local with same data, We are converting template file to stream before passing to BuildReport.

In Case if stream is of sharepoint template

Document load time: 100ms
Report generation time: 1400ms == This number is incresing in case of sharepoint
Document save time: 100ms

In Case if stream is of local template

Document load time: 100ms
Report generation time: 300ms
Document save time: 100ms

JSON

     {
         "part": "",
         "Data": [
           {
             "deck": "",
             "fab": [
               {
                 "fam": "",
                 "color": "",
                 "ModelNumber": "R",
                 "imageUrl": "",
                 "opennessFactor": ">10%",
                 "status": "Active"
               }
             ]
           }
         ]
       }

@alexey.noskov
Please suggest as it’s blocker to finalize the Liberary for template creation

@Gauravgarg01 As I can see image is loaded from web in your data source. Most likely when your run the code with Sharepoint the application cannot access the image and it take some time to skip it. Please modify the code like the following and run the test again:

//......
// Open document from stream
Document doc = new Document(docStream);
doc.ResourceLoadingCallback = new WordDocImageHandler();
//......
private class WordDocImageHandler : IResourceLoadingCallback
{
    public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)
    {
        return ResourceLoadingAction.Skip;
    }
}

@alexey.noskov

I tried the code but now the image is not loading into the report, Earlier it was visible in report ???

Image should be visible in report
image.png (2.7 KB)

FYI, Report build time reduce. But image should be visible

Document load time: 100ms
Report generation time: 10ms == This number is incresing in case of sharepoint
Document save time: 100ms

Also wanted to know why it is building report fast when we are using local template stream

@Gauravgarg01 Yes, the code I have provided for testing skips loading the external resources. This allowed us to determine that time different is caused by the time required to load the image in your different environments. This can be caused for example by firewall or internet speed. You can change IResourceLoadingCallback and load the external resources yourself and check the time required to load the image.

I am running my code on same environment i.e. on local for both Local template stream and sharepoint template stream

@alexey.noskov

Why it is taking more time to write on stream recevied from Sharepoint and less for local template stream

Can you help me to fix it

@Gauravgarg01 Is there a time difference when IResourceLoadingCallback is used to skip loading external resources?

yes

With local template: 1ms

With SharePoint Template: 3ms

@alexey.noskov

It is 2x. That impacting overall performance for large reports

@alexey.noskov
Please let me know if there is possibility for performance improvement

Otherwise it’s blocker for us

Please help on this

@Gauravgarg01 Is the exactly the same template is loaded from file and from SharePoint? Once document is loaded into a stream it is not connected to SharePoint or file. Once the document is loaded into Aspose.Words.Document object it is fully read into Aspose.Words DOM and is not connected to the stream or source from where the original file is loaded. So if the exactly the same template is used, there is no difference from where is it is loaded.