Commit 2a4045de authored by Robert Knight's avatar Robert Knight

Remove unnecessary `requestAnimationFrame` callbacks in `Guest`

Profiling anchoring of large numbers of annotations in Chrome showed
that there was significant overhead for scheduling and
executing `requestAnimationFrame` callbacks. In the case of `Guest.anchor`, the
callback often did nothing (it called `removeHighlights` with an empty
array).

There isn't a need for this any more AFAICS so just invoke the logic
synchronously, which is much cheaper.
parent 817d82f4
......@@ -510,7 +510,7 @@ export default class Guest extends Delegator {
}
// Remove all the highlights that have no corresponding target anymore.
requestAnimationFrame(() => removeHighlights(deadHighlights));
removeHighlights(deadHighlights);
// Anchor any targets of this annotation that are not anchored already.
for (let target of annotation.target) {
......@@ -542,10 +542,8 @@ export default class Guest extends Delegator {
this.anchors = anchors;
requestAnimationFrame(() => {
removeHighlights(unhighlight);
this.plugins.BucketBar?.update();
});
removeHighlights(unhighlight);
this.plugins.BucketBar?.update();
}
/**
......
......@@ -77,8 +77,6 @@ describe('Guest', () => {
};
notifySelectionChanged = null;
sinon.stub(window, 'requestAnimationFrame').yields();
fakeCrossFrame = {
onConnect: sinon.stub(),
on: sinon.stub(),
......@@ -114,7 +112,6 @@ describe('Guest', () => {
});
afterEach(() => {
window.requestAnimationFrame.restore();
sandbox.restore();
$imports.$restore();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment