OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 95 forks source link

Empty context.sync is slow on mac. #4812

Open peter-citeright opened 3 weeks ago

peter-citeright commented 3 weeks ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

Current behavior

Steps to reproduce

await Word.run(async (context) => {
                console.log({ pendingStatements: await context.debugInfo.pendingStatements });
                const t4 = performance.now();
                await context.sync();
                const t5 = performance.now();
                console.log({ timeToSync: t5 - t4 });
 });

The only pending statement is: ["var root = context.root;"]

yet at some points it takes up to 700ms. We do have other context syncs in other run functions in the document so not sure if that's affecting the performance, but what should we do to improve overall performance?

This 700ms overhead makes things worse especially when it comes to using insertHtml for content controls. Each insertion takes about 2000-3000ms.

shanshanzheng-dev commented 3 weeks ago

Hi @peter-citeright Thanks for reporting this issue. Could you tell us under what conditions might the pending duration surpass 700 milliseconds? I run this code many times, it doesn't take up to 700ms. image

peter-citeright commented 2 weeks ago

Were you testing on mac? And we have other syncs running in parallel. For example:

async function onSelectionChanged() {
        try {
            await Word.run(async (context) => {
                const document = context.document;
                const selection = document.getSelection();

                const contentControl = selection.parentContentControlOrNullObject;
                contentControl.load("id");

                document.contentControls.load("items");

                await context.sync();

                // ... do some processing
            });
        } catch (err) {
            if (process.env.NEXT_PUBLIC_APP_ENV !== "dev") {
                captureException(err);
            }
        }
    }
shanshanzheng-dev commented 2 weeks ago

Hi @peter-citeright The issue may be caused by several reasons, such as machine config. we'll take a look and report back if we have a suggestion for you. We unfortunately have no timelines to share at this point. It'll be helpful if you could share us some log, Thanks.