Skip to content

Commit

Permalink
Use export at each declaration
Browse files Browse the repository at this point in the history
It's getting a lot to duplicate.
  • Loading branch information
sebmarkbage committed Sep 17, 2024
1 parent f5621de commit a3894dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 81 deletions.
14 changes: 6 additions & 8 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ import {
Cloned,
} from './ReactFiberFlags';
import {
getCommitTime,
getCompleteTime,
commitTime,
completeTime,
pushNestedEffectDurations,
popNestedEffectDurations,
bubbleNestedEffectDurations,
Expand Down Expand Up @@ -504,7 +504,7 @@ function commitLayoutEffectOnFiber(
commitProfilerUpdate(
finishedWork,
current,
getCommitTime(),
commitTime,
profilerInstance.effectDuration,
);
} else {
Expand Down Expand Up @@ -2342,7 +2342,7 @@ export function reappearLayoutEffects(
commitProfilerUpdate(
finishedWork,
current,
getCommitTime(),
commitTime,
profilerInstance.effectDuration,
);
} else {
Expand Down Expand Up @@ -2573,9 +2573,7 @@ export function commitPassiveMountEffects(
finishedWork,
committedLanes,
committedTransitions,
enableProfilerTimer && enableComponentPerformanceTrack
? getCompleteTime()
: 0,
enableProfilerTimer && enableComponentPerformanceTrack ? completeTime : 0,
);
}

Expand Down Expand Up @@ -2762,7 +2760,7 @@ function commitPassiveMountOnFiber(
finishedWork.alternate,
// This value will still reflect the previous commit phase.
// It does not get reset until the start of the next commit phase.
getCommitTime(),
commitTime,
profilerInstance.passiveEffectDuration,
);
} else {
Expand Down
103 changes: 30 additions & 73 deletions packages/react-reconciler/src/ReactProfilerTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,14 @@ import * as Scheduler from 'scheduler';

const {unstable_now: now} = Scheduler;

export type ProfilerTimer = {
getCommitTime(): number,
isCurrentUpdateNested(): boolean,
markNestedUpdateScheduled(): void,
recordCommitTime(): void,
startProfilerTimer(fiber: Fiber): void,
stopProfilerTimerIfRunning(fiber: Fiber): void,
stopProfilerTimerIfRunningAndRecordDuration(fiber: Fiber): void,
stopProfilerTimerIfRunningAndRecordIncompleteDuration(fiber: Fiber): void,
syncNestedUpdateFlag(): void,
...
};

let completeTime: number = -0;
let commitTime: number = -0;
let profilerStartTime: number = -1.1;
let profilerEffectDuration: number = -0;
let componentEffectStartTime: number = -1.1;
let componentEffectEndTime: number = -1.1;

function pushNestedEffectDurations(): number {
export let completeTime: number = -0;
export let commitTime: number = -0;
export let profilerStartTime: number = -1.1;
export let profilerEffectDuration: number = -0;
export let componentEffectStartTime: number = -1.1;
export let componentEffectEndTime: number = -1.1;

export function pushNestedEffectDurations(): number {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return 0;
}
Expand All @@ -50,7 +37,7 @@ function pushNestedEffectDurations(): number {
return prevEffectDuration;
}

function popNestedEffectDurations(prevEffectDuration: number): number {
export function popNestedEffectDurations(prevEffectDuration: number): number {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return 0;
}
Expand All @@ -60,7 +47,9 @@ function popNestedEffectDurations(prevEffectDuration: number): number {
}

// Like pop but it also adds the current elapsed time to the parent scope.
function bubbleNestedEffectDurations(prevEffectDuration: number): number {
export function bubbleNestedEffectDurations(
prevEffectDuration: number,
): number {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return 0;
}
Expand All @@ -69,15 +58,15 @@ function bubbleNestedEffectDurations(prevEffectDuration: number): number {
return elapsedTime;
}

function resetComponentEffectTimers(): void {
export function resetComponentEffectTimers(): void {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return;
}
componentEffectStartTime = -1.1;
componentEffectEndTime = -1.1;
}

function pushComponentEffectStart(): number {
export function pushComponentEffectStart(): number {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return 0;
}
Expand All @@ -86,7 +75,7 @@ function pushComponentEffectStart(): number {
return prevEffectStart;
}

function popComponentEffectStart(prevEffectStart: number): void {
export function popComponentEffectStart(prevEffectStart: number): void {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return;
}
Expand Down Expand Up @@ -121,53 +110,45 @@ function popComponentEffectStart(prevEffectStart: number): void {
let currentUpdateIsNested: boolean = false;
let nestedUpdateScheduled: boolean = false;

function isCurrentUpdateNested(): boolean {
export function isCurrentUpdateNested(): boolean {
return currentUpdateIsNested;
}

function markNestedUpdateScheduled(): void {
export function markNestedUpdateScheduled(): void {
if (enableProfilerNestedUpdatePhase) {
nestedUpdateScheduled = true;
}
}

function resetNestedUpdateFlag(): void {
export function resetNestedUpdateFlag(): void {
if (enableProfilerNestedUpdatePhase) {
currentUpdateIsNested = false;
nestedUpdateScheduled = false;
}
}

function syncNestedUpdateFlag(): void {
export function syncNestedUpdateFlag(): void {
if (enableProfilerNestedUpdatePhase) {
currentUpdateIsNested = nestedUpdateScheduled;
nestedUpdateScheduled = false;
}
}

function getCompleteTime(): number {
return completeTime;
}

function recordCompleteTime(): void {
export function recordCompleteTime(): void {
if (!enableProfilerTimer) {
return;
}
completeTime = now();
}

function getCommitTime(): number {
return commitTime;
}

function recordCommitTime(): void {
export function recordCommitTime(): void {
if (!enableProfilerTimer) {
return;
}
commitTime = now();
}

function startProfilerTimer(fiber: Fiber): void {
export function startProfilerTimer(fiber: Fiber): void {
if (!enableProfilerTimer) {
return;
}
Expand All @@ -179,14 +160,16 @@ function startProfilerTimer(fiber: Fiber): void {
}
}

function stopProfilerTimerIfRunning(fiber: Fiber): void {
export function stopProfilerTimerIfRunning(fiber: Fiber): void {
if (!enableProfilerTimer) {
return;
}
profilerStartTime = -1;
}

function stopProfilerTimerIfRunningAndRecordDuration(fiber: Fiber): void {
export function stopProfilerTimerIfRunningAndRecordDuration(
fiber: Fiber,
): void {
if (!enableProfilerTimer) {
return;
}
Expand All @@ -199,7 +182,7 @@ function stopProfilerTimerIfRunningAndRecordDuration(fiber: Fiber): void {
}
}

function stopProfilerTimerIfRunningAndRecordIncompleteDuration(
export function stopProfilerTimerIfRunningAndRecordIncompleteDuration(
fiber: Fiber,
): void {
if (!enableProfilerTimer) {
Expand All @@ -214,7 +197,7 @@ function stopProfilerTimerIfRunningAndRecordIncompleteDuration(
}
}

function recordEffectDuration(fiber: Fiber): void {
export function recordEffectDuration(fiber: Fiber): void {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return;
}
Expand All @@ -234,7 +217,7 @@ function recordEffectDuration(fiber: Fiber): void {
}
}

function startEffectTimer(): void {
export function startEffectTimer(): void {
if (!enableProfilerTimer || !enableProfilerCommitHooks) {
return;
}
Expand All @@ -245,7 +228,7 @@ function startEffectTimer(): void {
}
}

function transferActualDuration(fiber: Fiber): void {
export function transferActualDuration(fiber: Fiber): void {
// Transfer time spent rendering these children so we don't lose it
// after we rerender. This is used as a helper in special cases
// where we should count the work of multiple passes.
Expand All @@ -256,29 +239,3 @@ function transferActualDuration(fiber: Fiber): void {
child = child.sibling;
}
}

export {
getCompleteTime,
recordCompleteTime,
getCommitTime,
recordCommitTime,
isCurrentUpdateNested,
markNestedUpdateScheduled,
recordEffectDuration,
resetNestedUpdateFlag,
startEffectTimer,
startProfilerTimer,
stopProfilerTimerIfRunning,
stopProfilerTimerIfRunningAndRecordDuration,
stopProfilerTimerIfRunningAndRecordIncompleteDuration,
syncNestedUpdateFlag,
transferActualDuration,
pushNestedEffectDurations,
popNestedEffectDurations,
bubbleNestedEffectDurations,
resetComponentEffectTimers,
pushComponentEffectStart,
popComponentEffectStart,
componentEffectStartTime,
componentEffectEndTime,
};

0 comments on commit a3894dd

Please sign in to comment.