SetLicense(string licenseName) is very slow and uses a lot of CPU resource

Hi, we are on a trial for Aspose 21.5/.6 and have noticed that SetLicense is very slow indeed and uses a large chunk of CPU compared to the older versions we have (over 7 seconds!!!).
Is this just an issue with the trial software or is this an issue with Aspose PDF in general?

@BriCass

Would you please share the environment details like OS Name and Version, Application type? Also, please share how you are setting license? (using memory stream or file path?) We were not able to notice this slowness in license settings at our end. Please share the requested details so that we can further proceed accordingly.

Windows 10 Enterprise build 18363, Coded Test harness to test multiple versions of Aspose written under VS2017 in C# .Net 4.7.
Test harness is opening the DLLs assemblies both for Aspose v10 and for Aspose V21.5 and calling the license methods with the Lic file path. Aspose V10 is super fast at reading the license file but Aspose V21.5 takes ages (both work successfully).

Test harness Code
Stopwatch stopwatch = new Stopwatch();

        AppendOutputTb("Opening Dll Libaries and Licenses" + Environment.NewLine);

        stopwatch.Start();
        asposeOldAsposeVersion = LoadAssembly(OldVersionDllTb.Text);
        stopwatch.Stop();
        AppendOutputTb($"Opening Old Dll Libary took {stopwatch.ElapsedMilliseconds} ms" + Environment.NewLine);

        stopwatch.Start();
        SetLicense(asposeOldAsposeVersion, OldAsposeLicFileTb.Text);
        stopwatch.Stop();
        AppendOutputTb($"Opening Old Dll License took {stopwatch.ElapsedMilliseconds} ms" + Environment.NewLine);

        stopwatch.Start();
        asposeNewAsposeVersion = LoadAssembly(NewVersionDllTb.Text);
        stopwatch.Stop();
        AppendOutputTb($"Opening New Dll Libary took {stopwatch.ElapsedMilliseconds} ms" + Environment.NewLine);

        stopwatch.Start();
        SetLicense(asposeNewAsposeVersion, NewAsposeLicFileTb.Text);
        stopwatch.Stop();
        AppendOutputTb($"Opening New Dll License took {stopwatch.ElapsedMilliseconds} ms" + Environment.NewLine);

    public static void SetLicense(Assembly asposeAssembly, string licPath)
    {
        Type type = asposeAssembly.GetType("Aspose.Pdf.License", false, true);
        // Create an instance of the type
        object instance = Activator.CreateInstance(type);

        var objectTypesLic = new System.Type[1];
        objectTypesLic[0] = licPath.GetType();
        var methodLic = type.GetMethod("SetLicense", objectTypesLic);
        var parasLic = new object[1];
        parasLic[0] = (object)licPath;
        methodLic.Invoke(instance, parasLic);

        // Initialize license object
        //Aspose.Pdf.License license = new Aspose.Pdf.License();
        //try
        //{
        //    // Set license
        //    license.SetLicense("Aspose.Pdf.lic");
        //}
        //catch (Exception)
        //{
        //    // something went wrong
        //    throw;
        //}
        //Console.WriteLine("License set successfully.");
    }

Output…

Opening Dll Libaries and Licenses
Opening Old Dll Libary took 29 ms
Opening Old Dll License took 91 ms
Opening New Dll Libary took 102 ms
Opening New Dll License took 8205 ms

Opening the Aspose Dll for version 19.5 under the same trial license takes only 354ms…

“Opening New Dll License took 354 ms”

This is the PDF of the Ants Profiler for the slow call, as expected the method names are encrypted but if you want I can post the disassembled reflected code also?

AsposeV21.5SetLicSlow.pdf (30.2 KB)

@BriCass

We tested the scenario in our environment and noticed that the new version (21.6) took 1525ms to load the license from file. An investigation ticket as PDFNET-50142 has been logged in our issue tracking system for this case. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you.

Brian

Is there any update on when a fix to PDFNET-50142 would be released?

@BriCass

We are afraid that the earlier logged ticket is not yet reviewed. It will be analyzed and resolved on first come first serve basis. We will surely inform you as soon as we have some definite updates regarding its resolution. Please give us some time.

We are sorry for the inconvenience.

Hi, Is there any update on this as yet please?

@BriCass

We are afraid that the issue is not yet fully investigated due to other issues logged prior to it. We will surely analyze and fix it on first come first serve basis and let you know once we have definite updates regarding its resolution. Please give us some time.

We are sorry for the inconvenience.

Any update on this as yet?

Brian

@BriCass

We regret to inform you that the earlier logged ticket is not yet resolved. We could not complete its investigation due to other issues in the queue. However, we have recorded your concerns and will surely inform you as soon as some definite progress is made towards ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

Any update on getting this fixed as yet? This has been a long time for a “paid for” product to get this sorted.

@BriCass

Please accept our humble apology for the inconvenience and the delay you have been facing. Please note that the licensing module is a core component of the API and any changes or addition to this module can effect other internal components and basic functioning of the API. These factors make the ticket complex in nature and that is why the ticket is taking more time to get resolved.

Nevertheless, your concerns have already been recorded and you will surely be notified via this forum thread as soon as some certain news is available about ticket resolution. We greatly appreciate your patience and comprehension in this regard.

We apologize for the inconvenience.

What we’re seeing is very similar to this user’s issue. Calls to SetLicense() take multiple seconds and spike the CPU. Looks like their problem was specific to Aspose.PDF, but we’re experiencing it with every library. PDFNET-50142 is their internal ticket.

We just need to know what it’s doing in the background. It might be related to antivirus scanning things that get loaded into memory, or manipulating reg keys or something. If we know exactly what that call does, we can tell the antivirus to ignore it, or just simulate it so that we don’t have to make the call in the first place.

@srtrout_nsa_gov

We have already escalated the issue priority to the next level and have recorded your comments under the ticket as well. As soon as its investigation is complete and we have some feedback to share, we will inform in this forum thread. Please be patient and spare us some time.

We apologize for the inconvenience.

Be patient?, it’s been over 2.5 years since the problem was first raised :frowning:

@BriCass

We understand your concerns. However, resolution time of a ticket depends upon its complexity and number of API components involve in its fix. The ticket logged here is quite complex and is taking certain amount of time while we are also working parallel on other tasks and the issues. Nevertheless, we will let you as soon as some definite updates are available. Your patience is highly appreciated in this regard.

I’ve just been working through this myself to speed up the Startup of our web application. We were running with the License as an embedded resource, as recommended, and then passing the name of the resource.

For me, what improved matters is getting the resource stream myself and then passing that to the License engine:

var assembly = Assembly.GetExecutingAssembly();
using (Stream license = assembly.GetManifestResourceStream("XYZ.Aspose.Total.lic"))
{
    if (license != null)
    {
        license.Position = 0;
        Aspose.Slides.License slideslicense = new Aspose.Slides.License();
        slideslicense?.SetLicense(license);
....

The name of the resource gets mangled so I would breakpoint after assembly and then run

assembly.GetManifestResourceNames()
in the immediate box to see what the full name of the resource is.

If you are not using embedded resources, as I do, then perhaps you getting the FileStream of the license file yourself rather than have Aspose hunt around would speed things up as it did with me.

1 Like

@Michael_Bond

Thanks for sharing this information. It could definitely help others facing similar case. Please feel free to create a new topic in case you need any kind of assistance.