[Performance]: UpdatePageLayout called too often

Peformance

Document.UpdatePageLayout called to often, even if document not modified

Issue

Aspose.Words.Document.UpdateFields (1 call -> 233 calls to update page layout)
Aspose.Words.Layout.LayoutCollector.GetStartPageIndex (1526 calls -> 279 calls to update page layout)

calls Aspose.Words.Document.UpdatePageLayout too often and 98% spent for update page layout even if nothing modified

Code

There’s simple enumerator which goes thought Aspose.Words.Document child nodes (deep) and uses LayoutCollector to get start page index

namespace Fiddle
{
    using System.Collections.Generic;
    using Aspose.Words;
    using Aspose.Words.Layout;
    using MoreLinq;

    public class DocumentAnalyser
    {
        private readonly Aspose.Words.Document _document;
        private readonly IDictionary<int, LinkedList<Node>> _nodesByPages = new Dictionary<int, LinkedList<Node>>();

        public DocumentAnalyser(Aspose.Words.Document document)
        {
            _document = document;
        }

        public void Analyse()
        {
            _document.UpdateTableLayout();
            _document.UpdatePageLayout();
            _document.UpdateFields();
            CreateNodesByPageMap();
        }

        private void CreateNodesByPageMap()
        {
            var collector = new LayoutCollector(_document);

            // in shapshots: there 1526 nodes
            _document.GetChildNodes(NodeType.Any, true)
                .ForEach(
                    (node) =>
                    {
                        var page = collector.GetStartPageIndex(node);
                        LinkedList<Node> list = null;
                        if (_nodesByPages.ContainsKey(page))
                        {
                            list = _nodesByPages[page];
                        }
                        else
                        {
                            list = new LinkedList<Node>();
                            _nodesByPages[page] = list;
                        }

                        list.AddLast(node);
                    });
        }
    }
}

Profiler snapshots:
snapshot-1.png (101.1 KB)
snapshot-2.png (94.2 KB)

@siarheiskalaban

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Thank you for reply
I sent you document via messaging

@siarheiskalaban

We are investigating this issue and will get back to you soon.

@siarheiskalaban

We have tested the scenario using the latest version of Aspose.Words for .NET 19.7 with Visual Studio 2017. We have not managed to reproduce this issue at our end.

Could you please share the steps that you are using to reproduce this issue at our end? Thanks for your cooperation.

Thank you, for your help
I’ll create test project and share it with you