lkosson / reportviewercore

Recompilation of Microsoft.ReportViewer for .NET Core 3.1+
427 stars 123 forks source link

Generating pdf report is slow #153

Closed AntonVonDelta closed 1 year ago

AntonVonDelta commented 1 year ago

In production our report is taking too long to generate , ~6 seconds which adds up quickly when generating many reports. In local dev environment and light load on the server the report performs very well with ~700ms.

I found this discussion about the issue.

However the solution applies to Net Framework. Is this library affected by the same bug? Can it be solved? What solution might exist to the issue?

lkosson commented 1 year ago

Try running a CPU profiler to collect call trees to determine the actual cause of slowdowns. The issue described in provided link doesn't apply to .NET Core, as there are no appdomains, sandboxing or CAS to isolate report's expression code.

AntonVonDelta commented 1 year ago

Is there any part of the report generating process that can be optimized (from outisde the library)? From my analysis I saw that creating the LocalReport variable is taking ~1s so I think that is a possible optimisation case for us (caching the variable and reusing).

If I reuse that variable and also reuse the instance for the same type of report but with different data, will it cut down on some of the time spent in Execute? I am not familiar with the internals if the library so I was wondering if some speedup can be gained here.

AntonVonDelta commented 1 year ago

I found in the library a call to LocalService::CompileReport which sets the rebuild flag to true. Changing it would seems to reduce the bulk of the time spent there.

Is there in the library a functionality/api that allows the report to be reused without recompilation? In my testing the compiling of the report takes a lot of time.

lkosson commented 1 year ago

Not much changed in that regard in this version of ReportViewer. You should be able to cache LocalReport and rebind parameters/data sources to skip recompiling large reports on every request.

AntonVonDelta commented 1 year ago

I managed to cache the report but I am not sure that the parameters will behave correctly. SetParameters seems to update the parameters already used in the report. If the new parameter list does not contain a previously used parameter then an old value will be used.

Is there a way to clear those too?

lkosson commented 1 year ago

I don't think so. Better pass all the parameters to be sure nothing gets reused.