preprocessData() — react Function Reference
Architecture documentation for the preprocessData() function in preprocessData.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD be28072d_a059_0346_2a4c_412726599426["preprocessData()"] a3f7147d_da0b_56dc_ffc9_a9e2bbc4526a["preprocessData.js"] be28072d_a059_0346_2a4c_412726599426 -->|defined in| a3f7147d_da0b_56dc_ffc9_a9e2bbc4526a 950f17e5_f6a0_7ca5_a5b3_8fa49f95fe1b["preprocessFlamechart()"] be28072d_a059_0346_2a4c_412726599426 -->|calls| 950f17e5_f6a0_7ca5_a5b3_8fa49f95fe1b 7e379096_4ef1_e90c_7e2b_b822b6321992["processTimelineEvent()"] be28072d_a059_0346_2a4c_412726599426 -->|calls| 7e379096_4ef1_e90c_7e2b_b822b6321992 style be28072d_a059_0346_2a4c_412726599426 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-devtools-timeline/src/import-worker/preprocessData.js lines 1009–1174
export default async function preprocessData(
timeline: TimelineEvent[],
): Promise<TimelineData> {
const flamechart = preprocessFlamechart(timeline);
const laneToReactMeasureMap: Map<ReactLane, Array<ReactMeasure>> = new Map();
for (let lane: ReactLane = 0; lane < REACT_TOTAL_NUM_LANES; lane++) {
laneToReactMeasureMap.set(lane, []);
}
const profilerData: TimelineData = {
batchUIDToMeasuresMap: new Map(),
componentMeasures: [],
duration: 0,
flamechart,
internalModuleSourceToRanges: new Map(),
laneToLabelMap: new Map(),
laneToReactMeasureMap,
nativeEvents: [],
networkMeasures: [],
otherUserTimingMarks: [],
reactVersion: null,
schedulingEvents: [],
snapshots: [],
snapshotHeight: 0,
startTime: 0,
suspenseEvents: [],
thrownErrors: [],
};
// Sort `timeline`. JSON Array Format trace events need not be ordered. See:
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.f2f0yd51wi15
timeline = timeline.filter(Boolean).sort((a, b) => (a.ts > b.ts ? 1 : -1));
// Events displayed in flamechart have timestamps relative to the profile
// event's startTime. Source: https://github.com/v8/v8/blob/44bd8fd7/src/inspector/js_protocol.json#L1486
//
// We'll thus expect there to be a 'Profile' event; if there is not one, we
// can deduce that there are no flame chart events. As we expect React
// scheduling profiling user timing marks to be recorded together with browser
// flame chart events, we can futher deduce that the data is invalid and we
// don't bother finding React events.
const indexOfProfileEvent = timeline.findIndex(
event => event.name === 'Profile',
);
if (indexOfProfileEvent === -1) {
return profilerData;
}
// Use Profile event's `startTime` as the start time to align with flame chart.
// TODO: Remove assumption that there'll only be 1 'Profile' event. If this
// assumption does not hold, the chart may start at the wrong time.
profilerData.startTime = timeline[indexOfProfileEvent].args.data.startTime;
profilerData.duration =
(timeline[timeline.length - 1].ts - profilerData.startTime) / 1000;
const state: ProcessorState = {
asyncProcessingPromises: [],
batchUID: 0,
currentReactComponentMeasure: null,
internalModuleCurrentStackFrame: null,
internalModuleStackStringSet: new Set(),
measureStack: [],
nativeEventStack: [],
nextRenderShouldGenerateNewBatchID: true,
potentialLongEvents: [],
potentialLongNestedUpdate: null,
potentialLongNestedUpdates: [],
potentialSuspenseEventsOutsideOfTransition: [],
requestIdToNetworkMeasureMap: new Map(),
uidCounter: 0,
unresolvedSuspenseEvents: new Map(),
};
timeline.forEach(event => processTimelineEvent(event, profilerData, state));
if (profilerVersion === null) {
if (
profilerData.schedulingEvents.length === 0 &&
profilerData.batchUIDToMeasuresMap.size === 0
) {
Domain
Subdomains
Source
Frequently Asked Questions
What does preprocessData() do?
preprocessData() is a function in the react codebase, defined in packages/react-devtools-timeline/src/import-worker/preprocessData.js.
Where is preprocessData() defined?
preprocessData() is defined in packages/react-devtools-timeline/src/import-worker/preprocessData.js at line 1009.
What does preprocessData() call?
preprocessData() calls 2 function(s): preprocessFlamechart, processTimelineEvent.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free