mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
refactor[react-devtools/fiber/renderer]: optimize durations resolution (#31118)
Stacked on https://github.com/facebook/react/pull/31117. No need for sending long float numbers and to have resolution less than a microsecond, we end up formatting it on a Frontend side: https://github.com/facebook/react/blob/6c7b41da3de12be2d95c60181b3fe896f824f13a/packages/react-devtools-shared/src/devtools/views/Profiler/utils.js#L359-L360
This commit is contained in:
@@ -44,6 +44,7 @@ import {
|
||||
} from 'react-devtools-shared/src/utils';
|
||||
import {
|
||||
formatConsoleArgumentsToSingleString,
|
||||
formatDurationToMicrosecondsGranularity,
|
||||
gt,
|
||||
gte,
|
||||
parseSourceFromComponentStack,
|
||||
@@ -5074,8 +5075,14 @@ export function attach(
|
||||
const fiberSelfDurations: Array<[number, number]> = [];
|
||||
for (let i = 0; i < durations.length; i += 3) {
|
||||
const fiberID = durations[i];
|
||||
fiberActualDurations.push([fiberID, durations[i + 1]]);
|
||||
fiberSelfDurations.push([fiberID, durations[i + 2]]);
|
||||
fiberActualDurations.push([
|
||||
fiberID,
|
||||
formatDurationToMicrosecondsGranularity(durations[i + 1]),
|
||||
]);
|
||||
fiberSelfDurations.push([
|
||||
fiberID,
|
||||
formatDurationToMicrosecondsGranularity(durations[i + 2]),
|
||||
]);
|
||||
}
|
||||
|
||||
commitData.push({
|
||||
@@ -5083,11 +5090,18 @@ export function attach(
|
||||
changeDescriptions !== null
|
||||
? Array.from(changeDescriptions.entries())
|
||||
: null,
|
||||
duration: maxActualDuration,
|
||||
effectDuration,
|
||||
duration:
|
||||
formatDurationToMicrosecondsGranularity(maxActualDuration),
|
||||
effectDuration:
|
||||
effectDuration !== null
|
||||
? formatDurationToMicrosecondsGranularity(effectDuration)
|
||||
: null,
|
||||
fiberActualDurations,
|
||||
fiberSelfDurations,
|
||||
passiveEffectDuration,
|
||||
passiveEffectDuration:
|
||||
passiveEffectDuration !== null
|
||||
? formatDurationToMicrosecondsGranularity(passiveEffectDuration)
|
||||
: null,
|
||||
priorityLevel,
|
||||
timestamp: commitTime,
|
||||
updaters,
|
||||
|
||||
@@ -331,3 +331,12 @@ export function parseSourceFromComponentStack(
|
||||
|
||||
return parseSourceFromFirefoxStack(componentStack);
|
||||
}
|
||||
|
||||
// 0.123456789 => 0.123
|
||||
// Expects high-resolution timestamp in milliseconds, like from performance.now()
|
||||
// Mainly used for optimizing the size of serialized profiling payload
|
||||
export function formatDurationToMicrosecondsGranularity(
|
||||
duration: number,
|
||||
): number {
|
||||
return Math.round(duration * 1000) / 1000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user