JsonDataSource Initialization Extremely Slow with Large JSON Input

I’m using the LINQ Reporting Engine in Aspose.Words and passing a large JSON structure (~18,000 tokens) as the data source.

Currently, I’m instantiating the data source like this:

 var dataSource = new JsonDataSource(new MemoryStream(encoding.GetBytes(input.ToString())), options);
engine.BuildReport(doc, dataSource);

While generating the JSON and memory stream is fast, the constructor for JsonDataSource itself is taking a very long time — around 3 minutes — before the report generation even begins.

Is there a more efficient or recommended way to load large JSON inputs into the reporting engine?

@PramodMn

Cause

The slow initialization of the JsonDataSource when dealing with large JSON inputs is likely due to the deserialization process that occurs when the data source is created. This process can be resource-intensive, especially with a large JSON structure, leading to significant delays.

Solution

To improve the performance of loading large JSON inputs, consider the following approaches:

  1. Use a File Instead of MemoryStream: If your JSON data is stored in a file, you can directly pass the file path to the JsonDataSource constructor. This can reduce the overhead of creating a MemoryStream.

    var dataSource = new JsonDataSource("path/to/your/large.json", options);
    
  2. Optimize JsonDataLoadOptions: You can customize the JsonDataLoadOptions to suit your specific needs. For example, if you don’t need strict type checking or if you can skip certain parsing features, adjusting these options can improve performance.

    JsonDataLoadOptions options = new JsonDataLoadOptions();
    options.SimpleValueParseMode = JsonSimpleValueParseMode.Loose; // Use loose mode for faster parsing
    
  3. Profile and Optimize JSON Structure: If possible, simplify the JSON structure or reduce its size. This might involve removing unnecessary data or restructuring it to be more efficient for your reporting needs.

Code

Here’s an example of how to implement the above suggestions:

// Load JSON from a file instead of a MemoryStream
var options = new JsonDataLoadOptions();
options.SimpleValueParseMode = JsonSimpleValueParseMode.Loose; // Adjust parsing mode

var dataSource = new JsonDataSource("path/to/your/large.json", options);
engine.BuildReport(doc, dataSource);

Next Steps

  1. Test the performance with the file-based approach and optimized options.
  2. If the issue persists, profile the JSON structure for further optimizations.
  3. Monitor the performance and adjust the settings as needed based on your specific use case.

Please implement these suggestions and let me know how it goes!

Tried loading directly from a Json file, there is no improvement, still takes up approx. 3 minutes

@PramodMn Could you please attach the problematic input JSONT file here for testing? We will check the issue and provide you more information.

Please find a sample Large Json
SampleJson.zip (65.5 KB)

@PramodMn
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28457

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.