Skip to content

Commit

Permalink
Add a mechanism to help collecting performance profile while initiali…
Browse files Browse the repository at this point in the history
…zation process #3097
  • Loading branch information
piroor committed Feb 12, 2025
1 parent 464fe78 commit 4e6f8cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion webextensions/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
wait,
configs,
sanitizeForHTMLText,
waitUntilStartupOperationsUnblocked,
} from '/common/common.js';
import * as ApiTabs from '/common/api-tabs.js';
import * as Constants from '/common/constants.js';
Expand Down Expand Up @@ -107,7 +108,7 @@ export async function init() {
promisedWindows = getAllWindows();
}),
ContextualIdentities.init(),
configs.$loaded
configs.$loaded.then(waitUntilStartupOperationsUnblocked),
]));
MetricsData.add('init: prepare');
EventListenerManager.debug = configs.debug;
Expand Down
19 changes: 19 additions & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import EventListenerManager from '/extlib/EventListenerManager.js';
import * as Constants from './constants.js';

export const DEVICE_SPECIFIC_CONFIG_KEYS = mapAndFilter(`
blockStartupOperations
chunkedSyncDataLocal0
chunkedSyncDataLocal1
chunkedSyncDataLocal2
Expand Down Expand Up @@ -553,6 +554,7 @@ export const configs = new Configs({


debug: false,
blockStartupOperations: false, // to collect performance profile around the initialization process
runTestsParameters: '',
syncEnabled: true,
APIEnabled: true,
Expand Down Expand Up @@ -1216,6 +1218,23 @@ export function isFirefoxViewTab(tab) {
}


export function waitUntilStartupOperationsUnblocked() {
if (!configs.blockStartupOperations)
return;

return new Promise((resolve, _reject) => {
const waitUntilUblocked = key => {
if (key != 'blockStartupOperations' ||
configs[key])
return;
configs.$removeObserver(waitUntilUblocked);
resolve();
};
configs.$addObserver(waitUntilUblocked);
});
}


export function isLinux() {
return configs.enableLinuxBehaviors || /^Linux/i.test(navigator.platform);
}
Expand Down
3 changes: 2 additions & 1 deletion webextensions/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isMacOS,
isRTL,
notify,
waitUntilStartupOperationsUnblocked,
} from '/common/common.js';
import * as ApiTabs from '/common/api-tabs.js';
import * as Bookmark from '/common/bookmark.js';
Expand Down Expand Up @@ -193,7 +194,7 @@ export async function init() {

return tabs;
}),
configs.$loaded
configs.$loaded.then(waitUntilStartupOperationsUnblocked),
]);
MetricsData.add('browser.tabs.query finish, configs are loaded.');
EventListenerManager.debug = configs.debug;
Expand Down

0 comments on commit 4e6f8cd

Please sign in to comment.