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

fix: error when 2 perf markers are stacked #865

Merged
merged 1 commit into from Dec 12, 2018
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
19 changes: 17 additions & 2 deletions packages/@lwc/engine/src/framework/performance-timing.ts
Expand Up @@ -24,7 +24,7 @@ const isUserTimingSupported: boolean =
typeof performance.measure === 'function' &&
typeof performance.clearMeasures === 'function';

function getMarkName(vm: VM, phase: MeasurementPhase): string {
function getMarkName(vm: VM, phase: MeasurementPhase | GlobalMeasurementPhase): string {
return `<${vm.def.name} (${vm.uid})> - ${phase}`;
}

Expand Down Expand Up @@ -64,6 +64,21 @@ function _endGlobalMeasure(phase: GlobalMeasurementPhase) {
performance.clearMeasures(phase);
}

export const startGlobalMeasure = isUserTimingSupported ? _startGlobalMeasure : noop;
function _startHydrateMeasure(vm: VM) {
performance.mark(getMarkName(vm, GlobalMeasurementPhase.HYDRATE));
}

function _endHydrateMeasure(vm: VM) {
const phase = GlobalMeasurementPhase.HYDRATE;
const name = getMarkName(vm, phase);

performance.measure(phase, name);
performance.clearMarks(name);
performance.clearMeasures(phase);
}

export const startGlobalMeasure = isUserTimingSupported ? _startGlobalMeasure : noop;
export const endGlobalMeasure = isUserTimingSupported ? _endGlobalMeasure : noop;

export const startHydrateMeasure = isUserTimingSupported ? _startHydrateMeasure : noop;
export const endHydrateMeasure = isUserTimingSupported ? _endHydrateMeasure : noop;
8 changes: 3 additions & 5 deletions packages/@lwc/engine/src/framework/upgrade.ts
Expand Up @@ -8,7 +8,7 @@ import { isNativeShadowRootAvailable } from "../env/dom";
import { patchCustomElementProto } from "./patch";
import { getComponentDef, setElementProto } from "./def";
import { patchCustomElementWithRestrictions } from "./restrictions";
import { endGlobalMeasure, startGlobalMeasure, GlobalMeasurementPhase } from "./performance-timing";
import { startHydrateMeasure, endHydrateMeasure } from "./performance-timing";
import { appendChild, insertBefore, replaceChild, removeChild } from "../env/node";

const ConnectingSlot = createFieldName('connecting');
Expand Down Expand Up @@ -60,7 +60,6 @@ assign(Node.prototype, {
* then it throws a TypeError.
*/
export function createElement(sel: string, options: any = {}): HTMLElement {
startGlobalMeasure(GlobalMeasurementPhase.INIT);
if (!isObject(options) || isNull(options)) {
throw new TypeError();
}
Expand Down Expand Up @@ -98,17 +97,16 @@ export function createElement(sel: string, options: any = {}): HTMLElement {
createVM(sel, element, Ctor, { mode, fallback, isRoot: true });
// Handle insertion and removal from the DOM manually
setInternalField(element, ConnectingSlot, () => {
startGlobalMeasure(GlobalMeasurementPhase.HYDRATE);
const vm = getCustomElementVM(element);
startHydrateMeasure(vm);
removeVM(vm); // moving the element from one place to another is observable via life-cycle hooks
appendVM(vm);
renderVM(vm);
endGlobalMeasure(GlobalMeasurementPhase.HYDRATE);
endHydrateMeasure(vm);
});
setInternalField(element, DisconnectingSlot, () => {
const vm = getCustomElementVM(element);
removeVM(vm);
});
endGlobalMeasure(GlobalMeasurementPhase.INIT);
return element;
}