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 performance timing log #603

Merged
merged 1 commit into from May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/loader.ts
Expand Up @@ -10,7 +10,15 @@ import getAddOns from './addons';
import { getMicroAppStateActions } from './globalState';
import { FrameworkConfiguration, FrameworkLifeCycles, HTMLContentRender, LifeCycleFn, LoadableApp } from './interfaces';
import { createSandbox } from './sandbox';
import { Deferred, getDefaultTplWrapper, getWrapperId, toArray, validateExportLifecycle } from './utils';
import {
Deferred,
getDefaultTplWrapper,
getWrapperId,
performanceMark,
performanceMeasure,
toArray,
validateExportLifecycle,
} from './utils';

function assertElementExist(element: Element | null | undefined, msg?: string) {
if (!element) {
Expand Down Expand Up @@ -194,6 +202,13 @@ export async function loadApp<T extends object>(
lifeCycles?: FrameworkLifeCycles<T>,
): Promise<ParcelConfigObject> {
const { entry, name: appName } = app;
const appInstanceId = `${appName}_${+new Date()}`;

const markName = `[qiankun] App ${appInstanceId} Loading`;
if (process.env.NODE_ENV === 'development') {
performanceMark(markName);
}

const { singular = false, sandbox = true, ...importEntryOpts } = configuration;

// get the entry html content and script executor
Expand All @@ -206,8 +221,6 @@ export async function loadApp<T extends object>(
await (prevAppUnmountedDeferred && prevAppUnmountedDeferred.promise);
}

const appInstanceId = `${appName}_${+new Date()}`;

const strictStyleIsolation = typeof sandbox === 'object' && !!sandbox.strictStyleIsolation;

const appContent = getDefaultTplWrapper(appInstanceId)(template);
Expand Down Expand Up @@ -290,6 +303,12 @@ export async function loadApp<T extends object>(
prevAppUnmountedDeferred = new Deferred<void>();
}
},
async () => {
if (process.env.NODE_ENV === 'development') {
const measureName = `[qiankun] App ${appInstanceId} Loading Consuming`;
performanceMeasure(measureName, markName);
howel52 marked this conversation as resolved.
Show resolved Hide resolved
}
},
],
unmount: [
async () => execHooksChain(toArray(beforeUnmount), app),
Expand Down
21 changes: 21 additions & 0 deletions src/utils.ts
Expand Up @@ -55,3 +55,24 @@ class Deferred<T> {
}

export { Deferred };

const supportsUserTiming =
typeof performance !== 'undefined' &&
typeof performance.mark === 'function' &&
typeof performance.clearMarks === 'function' &&
typeof performance.measure === 'function' &&
typeof performance.clearMeasures === 'function';

export function performanceMark(markName: string) {
if (supportsUserTiming) {
performance.mark(markName);
}
}

export function performanceMeasure(measureName: string, markName: string) {
if (supportsUserTiming) {
performance.measure(measureName, markName);
performance.clearMarks(markName);
performance.clearMeasures(measureName);
}
}