Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-16719] [COMMUNITY] Debounce requestIdleCallback a single time every 100ms, as opposed to call requestIdleCallback on debounce method #12695

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.mock("../utils", () => {
const utils = jest.requireActual("../utils");
return {
...utils,
debounce: jest.fn((fn) => fn),
debounce: jest.fn((fn, wait) => setTimeout(() => fn(), wait)),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
}

if (!this.mutationsQueue.length) {
requestIdleCallbackPolyfill(debounce(this.processMutations, 100), { timeout: 500 });
// Collect all mutations and debounce the processing of those mutations by 100ms to ensure we don't process too many mutations at once.
debounce(this.processMutations, 100);
}
this.mutationsQueue.push(mutations);
};
Expand Down Expand Up @@ -982,7 +983,8 @@ export class CollectAutofillContentService implements CollectAutofillContentServ
const queueLength = this.mutationsQueue.length;

if (!this.domQueryService.pageContainsShadowDomElements()) {
this.checkPageContainsShadowDom();
// Checking if a page contains shadowDOM elements is a heavy operation and doesn't have to be done immediately, so we can call this within an idle moment on the event loop.
requestIdleCallbackPolyfill(this.checkPageContainsShadowDom, { timeout: 500 });
}

for (let queueIndex = 0; queueIndex < queueLength; queueIndex++) {
Expand Down
Loading