Add a performant deleteAllAnnotations API for Word in Office.js
Summary
In Word for Office.js we currently have to delete each annotation individually by id. This becomes extremely slow when there are many annotations. A single bulk operation to remove all annotations in the document would greatly improve performance and user experience.
Current behavior
Right now the only practical approach is to iterate over all annotation ids and call delete on each one. For example
await Word.run(async (context) => {
annotationIds.forEach((id) => {
const annotation = context.document.getAnnotationById(id);
annotation.delete();
});
await context.sync();
});
Even if we split the work into chunks and sync multiple times, performance is still poor when there are many annotations.
Scenario and performance impact
- Host Word
- API Office.js Word JavaScript API
- Platform tested: Mac OS, Windows user reports similar behavior
Data from our testing
- Number of annotations around ten thousand
- Deleting all annotations can take about fifteen to thirty seconds
- This is true even when
- We break the annotation ids into smaller batches
- We call delete on a subset and sync repeatedly
From an end user perspective this looks like the product is hanging and is a significant slowdown in workflows that rely heavily on annotations.
Requested feature
Introduce a bulk API on the Word object model to remove all annotations in a document in a single host operation. Examples
context.document.annotations.deleteAll()
or
context.document.deleteAllAnnotations()
Key requirements
- Delete all annotations in the current document in one operation
- Performance suitable for at least tens of thousands of annotations
- Consistent behavior across Word on Mac and Word on Windows
- Promise based pattern consistent with existing Word.run usage