Skip to content

Commit

Permalink
Enable scheduling profiler flag in react-dom/testing builds (facebook…
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored and nevilm-lt committed Apr 22, 2022
1 parent b04e4ce commit 7351136
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
8 changes: 5 additions & 3 deletions packages/react-devtools-shared/src/backend/profilingHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function createProfilingHooks({
reactVersion,
}: {|
getDisplayNameForFiber: (fiber: Fiber) => string | null,
getLaneLabelMap?: () => Map<Lane, string>,
getLaneLabelMap?: () => Map<Lane, string> | null,
reactVersion: string,
|}): DevToolsProfilingHooks {
function markMetadata() {
Expand Down Expand Up @@ -108,8 +108,10 @@ export function createProfilingHooks({

if (typeof getLaneLabelMap === 'function') {
const map = getLaneLabelMap();
const labels = Array.from(map.values()).join(',');
markAndClear(`--react-lane-labels-${labels}`);
if (map != null) {
const labels = Array.from(map.values()).join(',');
markAndClear(`--react-lane-labels-${labels}`);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type ReactRenderer = {
scheduleRefresh?: Function,
// 18.0+
injectProfilingHooks?: (profilingHooks: DevToolsProfilingHooks) => void,
getLaneLabelMap?: () => Map<Lane, string>,
getLaneLabelMap?: () => Map<Lane, string> | null,
...
};

Expand Down
22 changes: 13 additions & 9 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void {
injectedProfilingHooks = profilingHooks;
}

function getLaneLabelMap(): Map<Lane, string> {
const map: Map<Lane, string> = new Map();
function getLaneLabelMap(): Map<Lane, string> | null {
if (enableSchedulingProfiler) {
const map: Map<Lane, string> = new Map();

let lane = 1;
for (let index = 0; index < TotalLanes; index++) {
const label = ((getLabelForLane(lane): any): string);
map.set(lane, label);
lane *= 2;
}
let lane = 1;
for (let index = 0; index < TotalLanes; index++) {
const label = ((getLabelForLane(lane): any): string);
map.set(lane, label);
lane *= 2;
}

return map;
return map;
} else {
return null;
}
}

export function markCommitStarted(lanes: Lanes): void {
Expand Down
22 changes: 13 additions & 9 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,21 @@ function injectProfilingHooks(profilingHooks: DevToolsProfilingHooks): void {
injectedProfilingHooks = profilingHooks;
}

function getLaneLabelMap(): Map<Lane, string> {
const map: Map<Lane, string> = new Map();
function getLaneLabelMap(): Map<Lane, string> | null {
if (enableSchedulingProfiler) {
const map: Map<Lane, string> = new Map();

let lane = 1;
for (let index = 0; index < TotalLanes; index++) {
const label = ((getLabelForLane(lane): any): string);
map.set(lane, label);
lane *= 2;
}
let lane = 1;
for (let index = 0; index < TotalLanes; index++) {
const label = ((getLabelForLane(lane): any): string);
map.set(lane, label);
lane *= 2;
}

return map;
return map;
} else {
return null;
}
}

export function markCommitStarted(lanes: Lanes): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import typeof * as ExportsType from './ReactFeatureFlags.testing';

export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableDebugTracing = false;
export const enableSchedulingProfiler = false;
export const enableSchedulingProfiler = __PROFILE__;
export const warnAboutDeprecatedLifecycles = true;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = __PROFILE__;
Expand Down

0 comments on commit 7351136

Please sign in to comment.