Slow first execution

4 posts, 0 answers
  1. Jakob
    Jakob avatar
    2 posts
    Member since:
    Oct 2020

    Posted 29 Dec 2020 Link to this post

    Hello,

     

    I'm trying to work with Telerik PDF-Processing right now. But an issue appeared, that I have no clue how to solve.

    In this current project, time is a very important aspect, so it's necessary for me to save milliseconds everywhere i can. So I logged the time for all of the Processes and, I don't know why, the first time, i use the methods, it needs more time, than the other later runs.

    Here's a simple example out of this project:

     

     private List<RadFixedPage> GetAllAddingPages(List<string> pathList)
            {    
                List<RadFixedPage> AllPages = new List<RadFixedPage>();

                for (int i = 1; i < pathList.Count; i++)
                {
                    RadFixedPage read = provider.Import(File.ReadAllBytes(pathList[i])).Pages[0];
                    AllPages.Add(read);
                }
                return AllPages;
            }

     

    The method's supposed to read the first pages of every document, that is filled in the "PathList." 

    I've stopped the first run and it needed about 150-160ms to execute. The second run is all about 20ms. There are only 3 Files that've been loaded.

    So i tested more..

    If i only load a document, that has no Image inside, it needs about the same time on the first run. If afterwards a document is loaded with only an Image, it needs long time also (103ms). If I open 3 documents (Vectorgraphics, Images and Text) it needs the 150-160ms. 

     

    Is this a known issue, or can somebody maybe help me with this?

    This is only one example, where this problem appears. But if there is a solution for this one, i can maybe apply it to the other methods.

     

    Best regards

    Jakob

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2646 posts

    Posted 01 Jan Link to this post

    Hello Jakob,

    Thank you for the provided information. We are working with limited resources during the holidays so we will need some additional time to review this thread. We are going to contact you again within the next few working days.

    Regards,
    Martin Ivanov
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. Jakob
    Jakob avatar
    2 posts
    Member since:
    Oct 2020

    Posted 05 Jan in reply to Martin Ivanov Link to this post

    Hello Martin,

    Thank you for your reply. I hope, you've had some good holidays! 

    Since i wrote this questions, I've gone further with testing. I realized, that if i load a document, which contains all 3 types (Vector, Images, Text), it loads very slow (like i mentioned above). That's why i created an "init-Method" in the Startup of the Program. It loads a Sample-Document, and when it comes to time-sensitive processes, it is pretty fast, if you work with the same kinds of contents. But if the sample contains different text(fonts), or images, it also needs more time. Maybe it's caused because of some Fonts, that have to be loaded while runtime? 

    Maybe this is helping you with finding the solution. 

     

    Best regards,

    Jakob

  4. Georgi
    Admin
    Georgi avatar
    52 posts

    Posted 05 Jan Link to this post

    Hello Jakob,

    Thank you for sharing the details with us.

    If I am understanding correctly the scenario, you are experiencing performance issues on application start during cold startup vs warm startup. Am I right? If this is the case, on cold startup CLR components will need to be loaded by accessing the disk. On the other hand, on warm startup, such components are already loaded in memory from where can be reused, which causes the difference in the performance. The following guide discusses approaches to Improving WPF applications startup time. Although this article is discussed in the context of WPF applications, some of the principles may be applied to other .NET application types as well.

    Also, after a process is started, subsequent execution calls may perform differently due to the initialization of static members, loading assemblies, and JIT compilation of the method code after its first execution, as stated in the Compilation by the JIT Compiler article.

    Regarding the performance related to fonts, when a font is not embedded in the PDF document, the PdfProcessing library will try loading the font file from the fonts installed on the operating system. If the font is not found, a fallback mechanism may apply. In such a scenario, after an appropriate font is loaded and parsed, the font is registered using the FontsRepository class and will be available for the next method invocations. More information on how to register fonts can be found in the Registering a Font section of the documentation.

    I hope you will find this helpful.

    Regards,
    Georgi
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top