Skip to content

Commit

Permalink
[Fiber] Profiler - Use two separate functions instead of branch by fl…
Browse files Browse the repository at this point in the history
…ag (#30957)

Nit: I don't trust flags in hot code. While it can take somewhat longer
to compile two functions and JIT them. After that they don't need to
check branches. Also makes it clearer the purpose.

DiffTrain build for commit 3d95c43.
  • Loading branch information
sebmarkbage committed Sep 14, 2024
1 parent b42180d commit baaa97f
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 87 deletions.
2 changes: 1 addition & 1 deletion compiled-rn/VERSION_NATIVE_FB
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.0.0-native-fb-d3d4d3a4-20240913
19.0.0-native-fb-3d95c43b-20240913
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<2d89a3e686f85aa5ee5696aad303b4b0>>
* @generated SignedSource<<e4eab5c04819ff525ec966db4c05e91a>>
*/

"use strict";
Expand Down Expand Up @@ -5032,11 +5032,18 @@ __DEV__ &&
profilerStartTime = now();
0 > fiber.actualStartTime && (fiber.actualStartTime = profilerStartTime);
}
function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
function stopProfilerTimerIfRunningAndRecordDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
fiber.selfBaseDuration = elapsedTime;
profilerStartTime = -1;
}
}
function stopProfilerTimerIfRunningAndRecordIncompleteDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
overrideBaseTime && (fiber.selfBaseDuration = elapsedTime);
profilerStartTime = -1;
}
}
Expand Down Expand Up @@ -11149,7 +11156,7 @@ __DEV__ &&
else
switch (
(handler.mode & 2 &&
stopProfilerTimerIfRunningAndRecordDelta(handler, !0),
stopProfilerTimerIfRunningAndRecordDuration(handler),
markComponentRenderStopped(),
workInProgressSuspendedReason)
) {
Expand Down Expand Up @@ -11426,7 +11433,7 @@ __DEV__ &&
unitOfWork,
entangledRenderLanes
)),
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !0))
stopProfilerTimerIfRunningAndRecordDuration(unitOfWork))
: (current = runWithFiberInDEV(
unitOfWork,
beginWork,
Expand Down Expand Up @@ -11485,7 +11492,7 @@ __DEV__ &&
(current = beginWork(current, unitOfWork, entangledRenderLanes));
}
isProfilingMode &&
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !0);
stopProfilerTimerIfRunningAndRecordDuration(unitOfWork);
return current;
}
function throwAndUnwindWorkLoop(root, unitOfWork, thrownValue) {
Expand Down Expand Up @@ -11555,7 +11562,9 @@ __DEV__ &&
completedWork,
entangledRenderLanes
)),
stopProfilerTimerIfRunningAndRecordDelta(completedWork, !1));
stopProfilerTimerIfRunningAndRecordIncompleteDuration(
completedWork
));
if (null !== current) {
workInProgress = current;
return;
Expand All @@ -11579,7 +11588,7 @@ __DEV__ &&
return;
}
if (0 !== (unitOfWork.mode & 2)) {
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !1);
stopProfilerTimerIfRunningAndRecordIncompleteDuration(unitOfWork);
next = unitOfWork.actualDuration;
for (var child = unitOfWork.child; null !== child; )
(next += child.actualDuration), (child = child.sibling);
Expand Down Expand Up @@ -15124,11 +15133,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-native-fb-d3d4d3a4-20240913",
version: "19.0.0-native-fb-3d95c43b-20240913",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-native-fb-3d95c43b-20240913"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -15273,5 +15282,5 @@ __DEV__ &&
flushSyncWorkAcrossRoots_impl(0, !0));
}
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<4f55ec78358c8ebecf4eaa369cc81849>>
* @generated SignedSource<<1bf2ef454808c04dbe363a5699c9a59f>>
*/

"use strict";
Expand Down Expand Up @@ -9486,14 +9486,14 @@ function wrapFiber(fiber) {
}
var internals$jscomp$inline_1266 = {
bundleType: 0,
version: "19.0.0-native-fb-d3d4d3a4-20240913",
version: "19.0.0-native-fb-3d95c43b-20240913",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function (mockNode) {
mockNode = nodeToInstanceMap.get(mockNode);
return void 0 !== mockNode ? mockNode.internalInstanceHandle : null;
},
reconcilerVersion: "19.0.0-native-fb-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-native-fb-3d95c43b-20240913"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1267 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -9629,4 +9629,4 @@ exports.unstable_batchedUpdates = function (fn, a) {
flushSyncWorkAcrossRoots_impl(0, !0));
}
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b264040d9a17e92d86c094ff1ead550e>>
* @generated SignedSource<<2929f47cce484593e96e4514ec4d434b>>
*/

"use strict";
Expand Down Expand Up @@ -3660,11 +3660,18 @@ function startProfilerTimer(fiber) {
profilerStartTime = now();
0 > fiber.actualStartTime && (fiber.actualStartTime = profilerStartTime);
}
function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
function stopProfilerTimerIfRunningAndRecordDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
fiber.selfBaseDuration = elapsedTime;
profilerStartTime = -1;
}
}
function stopProfilerTimerIfRunningAndRecordIncompleteDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
overrideBaseTime && (fiber.selfBaseDuration = elapsedTime);
profilerStartTime = -1;
}
}
Expand Down Expand Up @@ -8603,8 +8610,7 @@ function handleThrow(root, thrownValue) {
);
else
switch (
(handler.mode & 2 &&
stopProfilerTimerIfRunningAndRecordDelta(handler, !0),
(handler.mode & 2 && stopProfilerTimerIfRunningAndRecordDuration(handler),
markComponentRenderStopped(),
workInProgressSuspendedReason)
) {
Expand Down Expand Up @@ -8830,7 +8836,7 @@ function performUnitOfWork(unitOfWork) {
0 !== (unitOfWork.mode & 2)
? (startProfilerTimer(unitOfWork),
(current = beginWork(current, unitOfWork, entangledRenderLanes)),
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !0))
stopProfilerTimerIfRunningAndRecordDuration(unitOfWork))
: (current = beginWork(current, unitOfWork, entangledRenderLanes));
unitOfWork.memoizedProps = unitOfWork.pendingProps;
null === current
Expand Down Expand Up @@ -8878,7 +8884,7 @@ function replaySuspendedUnitOfWork(unitOfWork) {
resetWorkInProgress(next, entangledRenderLanes)),
(current = beginWork(current, next, entangledRenderLanes));
}
isProfilingMode && stopProfilerTimerIfRunningAndRecordDelta(next, !0);
isProfilingMode && stopProfilerTimerIfRunningAndRecordDuration(next);
next = current;
unitOfWork.memoizedProps = unitOfWork.pendingProps;
null === next ? completeUnitOfWork(unitOfWork) : (workInProgress = next);
Expand Down Expand Up @@ -8937,7 +8943,7 @@ function completeUnitOfWork(unitOfWork) {
? (current = completeWork(current, completedWork, entangledRenderLanes))
: (startProfilerTimer(completedWork),
(current = completeWork(current, completedWork, entangledRenderLanes)),
stopProfilerTimerIfRunningAndRecordDelta(completedWork, !1));
stopProfilerTimerIfRunningAndRecordIncompleteDuration(completedWork));
if (null !== current) {
workInProgress = current;
return;
Expand All @@ -8960,7 +8966,7 @@ function unwindUnitOfWork(unitOfWork, skipSiblings) {
return;
}
if (0 !== (unitOfWork.mode & 2)) {
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !1);
stopProfilerTimerIfRunningAndRecordIncompleteDuration(unitOfWork);
next = unitOfWork.actualDuration;
for (var child = unitOfWork.child; null !== child; )
(next += child.actualDuration), (child = child.sibling);
Expand Down Expand Up @@ -10074,14 +10080,14 @@ function wrapFiber(fiber) {
}
var internals$jscomp$inline_1141 = {
bundleType: 0,
version: "19.0.0-native-fb-d3d4d3a4-20240913",
version: "19.0.0-native-fb-3d95c43b-20240913",
rendererPackageName: "react-test-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function (mockNode) {
mockNode = nodeToInstanceMap.get(mockNode);
return void 0 !== mockNode ? mockNode.internalInstanceHandle : null;
},
reconcilerVersion: "19.0.0-native-fb-d3d4d3a4-20240913",
reconcilerVersion: "19.0.0-native-fb-3d95c43b-20240913",
getLaneLabelMap: function () {
for (
var map = new Map(), lane = 1, index$138 = 0;
Expand Down Expand Up @@ -10232,4 +10238,4 @@ exports.unstable_batchedUpdates = function (fn, a) {
flushSyncWorkAcrossRoots_impl(0, !0));
}
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<598e1a1554be705744125c5f6e86546f>>
* @generated SignedSource<<151f049853714f91fd46ef5a8978deb0>>
*/

"use strict";
Expand Down Expand Up @@ -1705,7 +1705,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b8568e853b095ed822fa12f152e3121e>>
* @generated SignedSource<<304b6c7b540179b069a45ff09f35dbe5>>
*/

"use strict";
Expand Down Expand Up @@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<92d8fbd56fb11e8c6a3aad4c04d6df3c>>
* @generated SignedSource<<09bffda39d917b825e992af0d48176ef>>
*/

"use strict";
Expand Down Expand Up @@ -584,7 +584,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-native-fb-d3d4d3a4-20240913";
exports.version = "19.0.0-native-fb-3d95c43b-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3d4d3a46b014ab0f6edc443c19fcdba09105f20
3d95c43b8967d4dda1ec9a22f0d9ea4999fee8b8
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<d23230a057fe994a91ecee3cb9cf7716>>
* @generated SignedSource<<f22f4e59e1c8c1bd2c19eba25b7b92e9>>
*/

"use strict";
Expand Down Expand Up @@ -5918,11 +5918,18 @@ __DEV__ &&
profilerStartTime = now();
0 > fiber.actualStartTime && (fiber.actualStartTime = profilerStartTime);
}
function stopProfilerTimerIfRunningAndRecordDelta(fiber, overrideBaseTime) {
function stopProfilerTimerIfRunningAndRecordDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
fiber.selfBaseDuration = elapsedTime;
profilerStartTime = -1;
}
}
function stopProfilerTimerIfRunningAndRecordIncompleteDuration(fiber) {
if (0 <= profilerStartTime) {
var elapsedTime = now() - profilerStartTime;
fiber.actualDuration += elapsedTime;
overrideBaseTime && (fiber.selfBaseDuration = elapsedTime);
profilerStartTime = -1;
}
}
Expand Down Expand Up @@ -12297,7 +12304,7 @@ __DEV__ &&
else
switch (
(JSCompiler_temp.mode & 2 &&
stopProfilerTimerIfRunningAndRecordDelta(JSCompiler_temp, !0),
stopProfilerTimerIfRunningAndRecordDuration(JSCompiler_temp),
markComponentRenderStopped(),
workInProgressSuspendedReason)
) {
Expand Down Expand Up @@ -12606,7 +12613,7 @@ __DEV__ &&
unitOfWork,
entangledRenderLanes
)),
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !0))
stopProfilerTimerIfRunningAndRecordDuration(unitOfWork))
: (current = runWithFiberInDEV(
unitOfWork,
beginWork,
Expand Down Expand Up @@ -12665,7 +12672,7 @@ __DEV__ &&
(current = beginWork(current, unitOfWork, entangledRenderLanes));
}
isProfilingMode &&
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !0);
stopProfilerTimerIfRunningAndRecordDuration(unitOfWork);
return current;
}
function throwAndUnwindWorkLoop(
Expand Down Expand Up @@ -12760,7 +12767,9 @@ __DEV__ &&
completedWork,
entangledRenderLanes
)),
stopProfilerTimerIfRunningAndRecordDelta(completedWork, !1));
stopProfilerTimerIfRunningAndRecordIncompleteDuration(
completedWork
));
if (null !== current) {
workInProgress = current;
return;
Expand All @@ -12784,7 +12793,7 @@ __DEV__ &&
return;
}
if (0 !== (unitOfWork.mode & 2)) {
stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, !1);
stopProfilerTimerIfRunningAndRecordIncompleteDuration(unitOfWork);
next = unitOfWork.actualDuration;
for (var child = unitOfWork.child; null !== child; )
(next += child.actualDuration), (child = child.sibling);
Expand Down Expand Up @@ -17173,11 +17182,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-native-fb-d3d4d3a4-20240913",
version: "19.0.0-native-fb-3d95c43b-20240913",
rendererPackageName: "react-native-renderer",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-native-fb-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-native-fb-3d95c43b-20240913"
};
null !== extraDevToolsConfig &&
(internals.rendererConfig = extraDevToolsConfig);
Expand Down
Loading

0 comments on commit baaa97f

Please sign in to comment.