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

Begin to add performance marks #697

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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
24 changes: 24 additions & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,14 @@ export class Display extends EventDispatcher {
async _onStateChanged() {
if (this._historyChangeIgnore) { return; }

performance.mark('display:onStateChanged:start');

/** @type {?import('core').TokenObject} */
const token = {}; // Unique identifier token
this._setContentToken = token;
try {
// Clear
performance.mark('display:clear:start');
this._closePopups();
this._closeAllPopupMenus();
this._eventListeners.removeAllEventListeners();
Expand All @@ -799,8 +802,11 @@ export class Display extends EventDispatcher {
this._dictionaryEntries = [];
this._dictionaryEntryNodes = [];
this._elementOverflowController.clearElements();
performance.mark('display:clear:end');
performance.measure('display:clear', 'display:clear:start', 'display:clear:end');

// Prepare
performance.mark('display:prepare:start');
const urlSearchParams = new URLSearchParams(location.search);
let type = urlSearchParams.get('type');
if (type === null && urlSearchParams.get('query') !== null) { type = 'terms'; }
Expand All @@ -809,7 +815,10 @@ export class Display extends EventDispatcher {
this._queryParserVisibleOverride = (fullVisible === null ? null : (fullVisible !== 'false'));

this._historyHasChanged = true;
performance.mark('display:prepare:end');
performance.measure('display:prepare', 'display:prepare:start', 'display:prepare:end');

performance.mark('display:setContent:start');
// Set content
switch (type) {
case 'terms':
Expand All @@ -826,9 +835,13 @@ export class Display extends EventDispatcher {
this._clearContent();
break;
}
performance.mark('display:setContent:end');
performance.measure('display:setContent', 'display:setContent:start', 'display:setContent:end');
} catch (e) {
this.onError(toError(e));
}
performance.mark('display:onStateChanged:end');
performance.measure('display:onStateChanged', 'display:onStateChanged:start', 'display:onStateChanged:end');
}

/**
Expand Down Expand Up @@ -1309,6 +1322,7 @@ export class Display extends EventDispatcher {
const hasEnabledDictionaries = this._options ? this._options.dictionaries.some(({enabled}) => enabled) : false;

// Set query
performance.mark('display:setQuery:start');
let query = urlSearchParams.get('query');
if (query === null) { query = ''; }
let queryFull = urlSearchParams.get('full');
Expand All @@ -1320,6 +1334,8 @@ export class Display extends EventDispatcher {
queryOffset = Number.isFinite(queryOffset) ? Math.max(0, Math.min(queryFull.length - query.length, queryOffset)) : 0;
}
this._setQuery(query, queryFull, queryOffset);
performance.mark('display:setQuery:end');
performance.measure('display:setQuery', 'display:setQuery:start', 'display:setQuery:end');

let {state, content} = this._history;
let changeHistory = false;
Expand Down Expand Up @@ -1384,9 +1400,12 @@ export class Display extends EventDispatcher {
const container = this._container;
container.textContent = '';

performance.mark('display:contentUpdate:start');
this._triggerContentUpdateStart();

for (let i = 0, ii = dictionaryEntries.length; i < ii; ++i) {
performance.mark('display:createEntry:start');

if (i > 0) {
await promiseTimeout(1);
if (this._setContentToken !== token) { return; }
Expand All @@ -1408,6 +1427,9 @@ export class Display extends EventDispatcher {
}

this._elementOverflowController.addElements(entry);

performance.mark('display:createEntry:end');
performance.measure('display:createEntry', 'display:createEntry:start', 'display:createEntry:end');
}

if (typeof scrollX === 'number' || typeof scrollY === 'number') {
Expand All @@ -1419,6 +1441,8 @@ export class Display extends EventDispatcher {
}

this._triggerContentUpdateComplete();
performance.mark('display:contentUpdate:end');
performance.measure('display:contentUpdate', 'display:contentUpdate:start', 'display:contentUpdate:end');
}

/** */
Expand Down
Loading