Skip to content

Word API calls that are near-instant on Windows/Office 365 take longer on Mac #3982

Open
@smketterercr

Description

@smketterercr

Word API calls that are near-instant on Windows/Office 365 take longer on Mac

We are having performance issues on a browser extension on Word for Mac where no problems exist on Windows (or on Office 365).

We have looked into reducing the count of context.sync calls per the documentation. Each individual operation appears to take a few seconds, which is too slow when you need to do multiple operations that depend on multiple items. This leads to long delays when you are performing a lot of operations on content controls, as an example.

In our Word add-in, once you hit the button to run the function you can see it working, slowly going through and selecting the content controls and filling out the information. The end-to-end process takes about 15-25s to complete, even with attempts at preloading. I'd expect it to take a couple seconds at most, as it does on Windows.

See this Stack Overflow question for another user who is trying to do a similarly heavy operation.

Beyond context.sync, other API calls seem to have a noticeable delay on Mac as well. Getting and setting custom XML and the selectionChanged events appear to take longer on Mac.

Below is an example of a Word.run call which take a while to complete. I have included similar code in the sample repro that can be run through Script Lab. A couple questions:

  • Is there anything in the below example that can be improved upon from a performance perspective (is there a pattern for reducing context.sync calls even further)?
  • Is there a reason why the API performance is noticeably slower on Mac compared to Windows/Office 365?
// Sync list of content controls
await Word.run(async (context) => {
    const contentControls = context.document.contentControls;
    contentControls.load(["id", "tag", "items", "fields"]);
    await context.sync();

    if (contentControls.items.length === 0) {
        console.log("There aren't any content controls in this document so can't register event handlers.");
    } else {
        for (let control of contentControls.items) {
            control.load("tag");
        }
        await context.sync();
        let fields = new Word.FieldCollection();
        for (let control of contentControls.items) {
            try {
                const tag = control.tag ? JSON.parse(decode(control.tag)) : null;
                if (tag) {
                    controlData.push({ ...tag, controlId: control.id });
                } else {
                    fields = control.getRange().fields.load("items");
                }
            } catch (err) {
                console.error(err);
            }
        }
        await context.sync();
        if (fields) {
            for (const field of fields.items) {
                field.load("code");
            }
            await context.sync();
            for (let control of contentControls.items) {
                try {
                    for (const field of fields.items) {
                        const someContentControlCode = field.code.split("CC_CODE ")[1];
                        if (someContentControlCode) {
                            // do stuff
                        }
                    }
                } catch (err) {
                    console.error(err);
                }
            }
        }

        // do stuff
    }
});

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Mac
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Office version number: 16.80
  • Operating System: macOS Sonoma 14.2.1
  • Browser (if using Office on the web): N/A

Expected behavior

Office.js API calls on Word for Mac should take about as long as they take on other clients.

Current behavior

Office.js API calls on Word for Mac are substantially slower than other clients.

On the live example:

  • Word Office 365 takes ~35ms and selecting the content control is instant
  • Word for Mac takes approx 250-300ms and selecting the content control takes about 800-900ms

While a 800ms delay isn't huge, in a multi-step process the delays add up.

Link to live example(s)

https://gist.github.com/smketterercr/3099e9354832e1cdd03884fe85e9d967

Provide additional details

Context

We are developing a Word add-in that manipulates citations and footnotes. It works well on Windows but the performance on Mac is too slow for our purposes. Assuming we will need multiple context.sync calls for fetching nested items as well as performing operations on content controls it's unclear if we can optimize this to the point of having acceptable performance (i.e. getting the end-to-end process down to a few seconds).

Metadata

Metadata

Labels

Area: WordIssue related to Word add-insNeeds: attention 👋Waiting on Microsoft to provide feedback

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions