Skip to content

Commit

Permalink
Begin to add performance marks
Browse files Browse the repository at this point in the history
<rikaitan.link>ZTBkMzgxYjE4NGQ4MzczNTg3YTc2Y2U1NjY2ODY3Y2M3ZDhkZmRlMAo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Oct 13, 2024
1 parent 2c3b462 commit 0ed4045
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 0ed4045

Please sign in to comment.