60
throw Error(`Could not find profiling snapshots for root ${rootID}`);
61
}
62
63
+ const filteredCommitData = [];
64
+ const filteredOperations = [];
65
+
66
+ // Filter empty commits from the profiler data.
67
+ // It is very important to keep operations and commit data arrays perfect in sync.
68
+ // So we must use the same criteria to filter both.
69
+ // If these two arrays were to get out of sync, the profiler would runtime error.
70
+ // We choose to filter on commit metadata, rather than the operations array,
71
+ // because the latter may have false positives,
72
+ // (e.g. a commit that re-rendered a component with the same treeBaseDuration as before).
73
+ commitData.forEach((commitDataBackend, commitIndex) => {
74
+ if (commitDataBackend.fiberActualDurations.length > 0) {
75
+ filteredCommitData.push({
76
+ changeDescriptions:
77
+ commitDataBackend.changeDescriptions != null
78
+ ? new Map(commitDataBackend.changeDescriptions)
79
+ : null,
80
+ duration: commitDataBackend.duration,
81
+ fiberActualDurations: new Map(
82
+ commitDataBackend.fiberActualDurations,
83
+ ),
84
+ fiberSelfDurations: new Map(commitDataBackend.fiberSelfDurations),
85
+ interactionIDs: commitDataBackend.interactionIDs,
86
+ priorityLevel: commitDataBackend.priorityLevel,
87
+ timestamp: commitDataBackend.timestamp,
88
+ });
89
+ filteredOperations.push(operations[commitIndex]);
90
+ }
91
+ });
92
+
93
dataForRoots.set(rootID, {
64
- commitData: commitData.map((commitDataBackend, commitIndex) => ({
65
- changeDescriptions:
66
- commitDataBackend.changeDescriptions != null
67
- ? new Map(commitDataBackend.changeDescriptions)
68
- : null,
69
- duration: commitDataBackend.duration,
70
- fiberActualDurations: new Map(
71
- commitDataBackend.fiberActualDurations,
72
- ),
73
- fiberSelfDurations: new Map(commitDataBackend.fiberSelfDurations),
74
- interactionIDs: commitDataBackend.interactionIDs,
75
- priorityLevel: commitDataBackend.priorityLevel,
76
- timestamp: commitDataBackend.timestamp,
77
- })),
94
+ commitData: filteredCommitData,
95
+ displayName,
96
+ initialTreeBaseDurations: new Map(initialTreeBaseDurations),
97
+ interactionCommits: new Map(interactionCommits),
98
+ interactions: new Map(interactions),
99
+ operations: filteredOperations,
100
+ rootID,
101
+ snapshots,
102
+ });
103
+
104
+ dataForRoots.set(rootID, {
105
+ commitData: filteredCommitData,
106
displayName,
107
initialTreeBaseDurations: new Map(initialTreeBaseDurations),
108
interactionCommits: new Map(interactionCommits),
109
interactions: new Map(interactions),
82
- operations,
110
+ operations: filteredOperations,
111
rootID,
112
snapshots,
113
});