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

Add simple JS init performance trace #31459

Merged
merged 1 commit into from
Jun 22, 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
230 changes: 129 additions & 101 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,110 +94,138 @@ import {
import {initGlobalDropzone} from './features/dropzone.js';
import {initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.js';

// Init Gitea's Fomantic settings
initGiteaFomantic();
initDirAuto();
initSubmitEventPolyfill();

function callInitFunctions(functions) {
// Start performance trace by accessing a URL by "https://localhost/?_ui_performance_trace=1" or "https://localhost/?key=value&_ui_performance_trace=1"
// It is a quick check, no side effect so no need to do slow URL parsing.
const initStart = performance.now();
if (window.location.search.includes('_ui_performance_trace=1')) {
let results = [];
for (const func of functions) {
const start = performance.now();
func();
results.push({name: func.name, dur: performance.now() - start});
}
results = results.sort((a, b) => b.dur - a.dur);
for (let i = 0; i < 20 && i < results.length; i++) {
// eslint-disable-next-line no-console
console.log(`performance trace: ${results[i].name} ${results[i].dur.toFixed(3)}`);
}
} else {
for (const func of functions) {
func();
}
}
const initDur = performance.now() - initStart;
if (initDur > 500) {
console.error(`slow init functions took ${initDur.toFixed(3)}ms`);
}
}

onDomReady(() => {
initGlobalDropdown();
initGlobalTabularMenu();
initGlobalShowModal();
initGlobalFetchAction();
initGlobalTooltips();
initGlobalButtonClickOnEnter();
initGlobalButtons();
initGlobalCopyToClipboardListener();
initGlobalDropzone();
initGlobalEnterQuickSubmit();
initGlobalFormDirtyLeaveConfirm();
initGlobalDeleteButton();

initCommonOrganization();
initCommonIssueListQuickGoto();

initCompSearchUserBox();
initCompWebHookEditor();

initInstall();

initHeadNavbarContentToggle();
initFootLanguageMenu();

initCommentContent();
initContextPopups();
initHeatmap();
initImageDiff();
initMarkupAnchors();
initMarkupContent();
initSshKeyFormParser();
initStopwatch();
initTableSort();
initAutoFocusEnd();
initFindFileInRepo();
initCopyContent();

initAdminCommon();
initAdminEmails();
initAdminUserListSearchForm();
initAdminConfigs();
initAdminSelfCheck();

initDashboardRepoList();

initNotificationCount();
initNotificationsTable();

initOrgTeamSearchRepoBox();
initOrgTeamSettings();

initRepoActivityTopAuthorsChart();
initRepoArchiveLinks();
initRepoBranchButton();
initRepoCodeView();
initRepoCommentForm();
initRepoEllipsisButton();
initRepoDiffCommitBranchesAndTags();
initRepoEditor();
initRepoGraphGit();
initRepoIssueContentHistory();
initRepoIssueDue();
initRepoIssueList();
initRepoIssueSidebarList();
initArchivedLabelHandler();
initRepoIssueReferenceRepositorySearch();
initRepoIssueTimeTracking();
initRepoIssueWipTitle();
initRepoMigration();
initRepoMigrationStatusChecker();
initRepoProject();
initRepoPullRequestMergeInstruction();
initRepoPullRequestAllowMaintainerEdit();
initRepoPullRequestReview();
initRepoRelease();
initRepoReleaseNew();
initRepoSettingGitHook();
initRepoSettingSearchTeamBox();
initRepoSettingsCollaboration();
initRepoTemplateSearch();
initRepoTopicBar();
initRepoWikiForm();
initRepository();
initRepositoryActionView();
initRepositorySearch();
initRepoContributors();
initRepoCodeFrequency();
initRepoRecentCommits();

initCommitStatuses();
initCaptcha();

initUserAuthOauth2();
initUserAuthWebAuthn();
initUserAuthWebAuthnRegister();
initUserSettings();
initRepoDiffView();
initPdfViewer();
initScopedAccessTokenCategories();
initColorPickers();
callInitFunctions([
initGlobalDropdown,
initGlobalTabularMenu,
initGlobalShowModal,
initGlobalFetchAction,
initGlobalTooltips,
initGlobalButtonClickOnEnter,
initGlobalButtons,
initGlobalCopyToClipboardListener,
initGlobalDropzone,
initGlobalEnterQuickSubmit,
initGlobalFormDirtyLeaveConfirm,
initGlobalDeleteButton,

initCommonOrganization,
initCommonIssueListQuickGoto,

initCompSearchUserBox,
initCompWebHookEditor,

initInstall,

initHeadNavbarContentToggle,
initFootLanguageMenu,

initCommentContent,
initContextPopups,
initHeatmap,
initImageDiff,
initMarkupAnchors,
initMarkupContent,
initSshKeyFormParser,
initStopwatch,
initTableSort,
initAutoFocusEnd,
initFindFileInRepo,
initCopyContent,

initAdminCommon,
initAdminEmails,
initAdminUserListSearchForm,
initAdminConfigs,
initAdminSelfCheck,

initDashboardRepoList,

initNotificationCount,
initNotificationsTable,

initOrgTeamSearchRepoBox,
initOrgTeamSettings,

initRepoActivityTopAuthorsChart,
initRepoArchiveLinks,
initRepoBranchButton,
initRepoCodeView,
initRepoCommentForm,
initRepoEllipsisButton,
initRepoDiffCommitBranchesAndTags,
initRepoEditor,
initRepoGraphGit,
initRepoIssueContentHistory,
initRepoIssueDue,
initRepoIssueList,
initRepoIssueSidebarList,
initArchivedLabelHandler,
initRepoIssueReferenceRepositorySearch,
initRepoIssueTimeTracking,
initRepoIssueWipTitle,
initRepoMigration,
initRepoMigrationStatusChecker,
initRepoProject,
initRepoPullRequestMergeInstruction,
initRepoPullRequestAllowMaintainerEdit,
initRepoPullRequestReview,
initRepoRelease,
initRepoReleaseNew,
initRepoSettingGitHook,
initRepoSettingSearchTeamBox,
initRepoSettingsCollaboration,
initRepoTemplateSearch,
initRepoTopicBar,
initRepoWikiForm,
initRepository,
initRepositoryActionView,
initRepositorySearch,
initRepoContributors,
initRepoCodeFrequency,
initRepoRecentCommits,

initCommitStatuses,
initCaptcha,

initUserAuthOauth2,
initUserAuthWebAuthn,
initUserAuthWebAuthnRegister,
initUserSettings,
initRepoDiffView,
initPdfViewer,
initScopedAccessTokenCategories,
initColorPickers,
]);
});