no-bug - Improved initial startup performance and loading speeds, c=common, tabs, workspaces, t=perf

This commit is contained in:
Mr. M
2025-06-06 13:34:29 +02:00
parent a6d749a9c8
commit cf6a346749
5 changed files with 290 additions and 305 deletions

View File

@@ -1,8 +1,8 @@
diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
index 3d5173315812589c0b79beec5f0419fc37cb8868..c4216db9e414fbbaead6ecd89b40366b0d8a50c1 100644
index bcbfab4a3781ff3c7349115751b3830976eec4bf..1ab08a9344b16cbe791182fce3f6fbf59ca3df91 100644
--- a/browser/base/content/browser-init.js
+++ b/browser/base/content/browser-init.js
@@ -175,6 +175,8 @@ var gBrowserInit = {
@@ -186,6 +186,8 @@ var gBrowserInit = {
},
onLoad() {
@@ -11,11 +11,3 @@ index 3d5173315812589c0b79beec5f0419fc37cb8868..c4216db9e414fbbaead6ecd89b40366b
gBrowser.addEventListener("DOMUpdateBlockedPopups", e =>
PopupBlockerObserver.handleEvent(e)
);
@@ -310,6 +312,7 @@ var gBrowserInit = {
TelemetryTimestamps.add("delayedStartupStarted");
this._cancelDelayedStartup();
+ gZenWorkspaces.afterLoadInit();
gBrowser.addEventListener(
"PermissionStateChange",

View File

@@ -36,7 +36,6 @@
}
async #waitAndCleanup() {
await SessionStore.promiseAllWindowsRestored;
await SessionStore.promiseInitialized;
this.#cleanup();
}

View File

@@ -65,23 +65,10 @@
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
this._zenClickEventListener = this._onTabClick.bind(this);
gZenWorkspaces.addChangeListeners(this.onWorkspaceChange.bind(this));
await ZenPinnedTabsStorage.promiseInitialized;
gZenWorkspaces._resolvePinnedInitialized();
}
async onWorkspaceChange(newWorkspace, onInit) {
if (!this.enabled || PrivateBrowsingUtils.isWindowPrivate(window)) {
return;
}
if (onInit) {
await this._refreshPinnedTabs({ init: onInit });
this._hasFinishedLoading = true;
}
}
log(message) {
if (this._canLog) {
console.log(`[ZenPinnedTabManager] ${message}`);
@@ -149,13 +136,19 @@
return this._enabled && !gZenWorkspaces.privateWindowOrDisabled;
}
async _refreshPinnedTabs({ init = false } = {}) {
async refreshPinnedTabs({ init = false } = {}) {
await ZenPinnedTabsStorage.promiseInitialized;
await gZenWorkspaces.promiseSectionsInitialized;
await this._initializePinsCache();
(async () => {
// Execute in a separate task to avoid blocking the main thread
await SessionStore.promiseAllWindowsRestored;
await gZenWorkspaces.promiseInitialized;
await this._initializePinnedTabs(init);
if (init) {
this._resolveInitializedPinnedCache();
this._hasFinishedLoading = true;
}
})();
}
async _initializePinsCache() {
@@ -439,7 +432,7 @@
await this.savePin(pin);
this.resetPinChangedUrl(tab);
await this._refreshPinnedTabs();
await this.refreshPinnedTabs();
gZenUIManager.showToast('zen-pinned-tab-replaced');
}
@@ -482,7 +475,7 @@
return;
}
this.onLocationChange(browser);
await this._refreshPinnedTabs();
await this.refreshPinnedTabs();
}
async _removePinnedAttributes(tab, isClosing = false) {
@@ -508,7 +501,7 @@
tab.setAttribute('zen-workspace-id', workspace.uuid);
}
}
await this._refreshPinnedTabs();
await this.refreshPinnedTabs();
tab.dispatchEvent(
new CustomEvent('ZenPinnedTabRemoved', {
detail: { tab },
@@ -958,7 +951,7 @@
const uuid = tab.getAttribute('zen-pin-id');
await ZenPinnedTabsStorage.updatePinTitle(uuid, newTitle, isEdited, notifyObservers);
await this._refreshPinnedTabs();
await this.refreshPinnedTabs();
const browsers = Services.wm.getEnumerator('navigator:browser');
@@ -1110,8 +1103,4 @@
}
window.gZenPinnedTabManager = new ZenPinnedTabManager();
gZenPinnedTabManager.promisePinnedCacheInitialized = new Promise((resolve) => {
gZenPinnedTabManager._resolveInitializedPinnedCache = resolve;
});
}

View File

@@ -46,11 +46,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (this.privateWindowOrDisabled) {
return;
}
await Promise.all([
this.promiseDBInitialized,
this.promisePinnedInitialized,
SessionStore.promiseAllWindowsRestored,
]);
await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized]);
}
async init() {
@@ -119,6 +115,8 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
window.addEventListener('resize', this.onWindowResize.bind(this));
this.addPopupListeners();
await this.afterLoadInit();
}
log(...args) {
@@ -128,14 +126,15 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
async afterLoadInit() {
await SessionStore.promiseInitialized;
if (!this._hasInitializedTabsStrip) {
await this.delayedStartup();
}
await this.promiseSectionsInitialized;
this.log('gZenWorkspaces initialized');
await this.initializeWorkspaces();
await this.promiseSectionsInitialized;
// Non UI related initializations
this._initializeWorkspaceCreationIcons();
this._initializeWorkspaceTabContextMenus();
if (
Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) &&
this.workspaceEnabled &&
@@ -297,9 +296,6 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._pinnedTabsResizeObserver = new ResizeObserver(this.onPinnedTabsResize.bind(this));
await this.waitForPromises();
await this._createDefaultWorkspaceIfNeeded();
await this.initializeTabsStripSections();
this._resolveSectionsInitialized();
this._initializeEmptyTab();
}
async _createDefaultWorkspaceIfNeeded() {
@@ -375,6 +371,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
async initializeTabsStripSections() {
await SessionStore.promiseAllWindowsRestored;
const perifery = document.getElementById('tabbrowser-arrowscrollbox-periphery');
perifery.setAttribute('hidden', 'true');
const tabs = gBrowser.tabContainer.allTabs;
@@ -409,6 +406,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._hasInitializedTabsStrip = true;
this.registerPinnedResizeObserver();
this._fixIndicatorsNames(workspaces);
this._resolveSectionsInitialized();
}
getEssentialsSection(container = 0) {
@@ -836,26 +834,23 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
async initializeWorkspaces() {
if (this.workspaceEnabled) {
this._initializeWorkspaceCreationIcons();
this._initializeWorkspaceTabContextMenus();
await this.workspaceBookmarks();
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
let activeWorkspace = await this.getActiveWorkspace();
this.activeWorkspace = activeWorkspace?.uuid;
try {
if (activeWorkspace) {
window.gZenThemePicker = new ZenThemePicker();
await this.changeWorkspace(activeWorkspace, { onInit: true });
gBrowser.tabContainer._positionPinnedTabs();
await gZenThemePicker.onWorkspaceChange(activeWorkspace);
}
} catch (e) {
console.error('gZenWorkspaces: Error initializing theme picker', e);
}
this.onWindowResize();
if (window.gZenSessionStore) {
await gZenSessionStore.promiseInitialized;
}
await this.initializeTabsStripSections();
this._initializeEmptyTab();
await this.workspaceBookmarks();
await gZenPinnedTabManager.refreshPinnedTabs({ init: true });
await this.changeWorkspace(activeWorkspace, { onInit: true });
await this._selectStartPage();
this._fixTabPositions();
this._resolveInitialized();
@@ -869,7 +864,8 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
window.addEventListener('TabPinned', tabUpdateListener);
window.addEventListener('TabUnpinned', tabUpdateListener);
window.addEventListener('aftercustomization', tabUpdateListener);
}
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
}
async _selectStartPage() {
@@ -1412,18 +1408,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
);
}
async _propagateWorkspaceData({ ignoreStrip = false, clearCache = true } = {}) {
const currentWindowIsPrivate = this.isPrivateWindow;
await this.foreachWindowAsActive(async (browser) => {
// Do not update the window if workspaces are not enabled in it.
// For example, when the window is in private browsing mode.
if (
!browser.gZenWorkspaces.workspaceEnabled ||
browser.gZenWorkspaces.isPrivateWindow !== currentWindowIsPrivate
) {
return;
}
async _propagateWorkspaceDataForWindow(browser, { ignoreStrip = false, clearCache = true } = {}) {
let workspaceList = browser.document.getElementById('PanelUI-zen-workspaces-list');
const createWorkspaceElement = (workspace) => {
let element = browser.document.createXULElement('toolbarbutton');
@@ -1672,10 +1657,33 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
}
workspaceList.appendChild(createLastPositionDropTarget());
if (!ignoreStrip) {
browser.gZenWorkspaces._fixIndicatorsNames(workspaces);
}
}
async _propagateWorkspaceData({ ignoreStrip = false, clearCache = true, onInit = false } = {}) {
const currentWindowIsPrivate = this.isPrivateWindow;
if (onInit) {
if (currentWindowIsPrivate) return;
return await this._propagateWorkspaceDataForWindow(this.ownerWindow, {
ignoreStrip,
clearCache,
});
}
await this.foreachWindowAsActive(async (browser) => {
// Do not update the window if workspaces are not enabled in it.
// For example, when the window is in private browsing mode.
if (
!browser.gZenWorkspaces.workspaceEnabled ||
browser.gZenWorkspaces.isPrivateWindow !== currentWindowIsPrivate
) {
return;
}
this._propagateWorkspaceDataForWindow(browser, {
ignoreStrip,
clearCache,
}).catch(console.error);
});
}
@@ -2505,7 +2513,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
// Update workspace UI
await this._updateWorkspacesChangeContextMenu();
// gZenUIManager.updateTabsToolbar();
await this._propagateWorkspaceData({ clearCache: false });
await this._propagateWorkspaceData({ clearCache: false, onInit });
gZenThemePicker.onWorkspaceChange(workspace);

View File

@@ -584,7 +584,4 @@ var ZenWorkspaceBookmarksStorage = {
},
};
ZenWorkspacesStorage.promiseDBInitialized = new Promise((resolve) => {
ZenWorkspacesStorage._resolveDBInitialized = resolve;
ZenWorkspacesStorage.init();
});