97
}
98
99
export type GetTimelineData = () => TimelineData | null;
100
-export type ToggleProfilingStatus = (value: boolean) => void;
100
+export type ToggleProfilingStatus = (
101
+ value: boolean,
102
+ recordTimeline?: boolean,
103
+) => void;
104
105
type Response = {
106
getTimelineData: GetTimelineData,
842
}
843
}
844
842
- function toggleProfilingStatus(value: boolean) {
845
+ function toggleProfilingStatus(
846
+ value: boolean,
847
+ recordTimeline: boolean = false,
848
+ ) {
849
if (isProfiling !== value) {
850
isProfiling = value;
851
881
currentReactComponentMeasure = null;
882
currentReactMeasuresStack = [];
883
currentFiberStacks = new Map();
878
- currentTimelineData = {
879
- // Session wide metadata; only collected once.
880
- internalModuleSourceToRanges,
881
- laneToLabelMap: laneToLabelMap || new Map(),
882
- reactVersion,
883
-
884
- // Data logged by React during profiling session.
885
- componentMeasures: [],
886
- schedulingEvents: [],
887
- suspenseEvents: [],
888
- thrownErrors: [],
889
-
890
- // Data inferred based on what React logs.
891
- batchUIDToMeasuresMap: new Map(),
892
- duration: 0,
893
- laneToReactMeasureMap,
894
- startTime: 0,
895
-
896
- // Data only available in Chrome profiles.
897
- flamechart: [],
898
- nativeEvents: [],
899
- networkMeasures: [],
900
- otherUserTimingMarks: [],
901
- snapshots: [],
902
- snapshotHeight: 0,
903
- };
884
+ if (recordTimeline) {
885
+ currentTimelineData = {
886
+ // Session wide metadata; only collected once.
887
+ internalModuleSourceToRanges,
888
+ laneToLabelMap: laneToLabelMap || new Map(),
889
+ reactVersion,
890
+
891
+ // Data logged by React during profiling session.
892
+ componentMeasures: [],
893
+ schedulingEvents: [],
894
+ suspenseEvents: [],
895
+ thrownErrors: [],
896
+
897
+ // Data inferred based on what React logs.
898
+ batchUIDToMeasuresMap: new Map(),
899
+ duration: 0,
900
+ laneToReactMeasureMap,
901
+ startTime: 0,
902
+
903
+ // Data only available in Chrome profiles.
904
+ flamechart: [],
905
+ nativeEvents: [],
906
+ networkMeasures: [],
907
+ otherUserTimingMarks: [],
908
+ snapshots: [],
909
+ snapshotHeight: 0,
910
+ };
911
+ }
912
nextRenderShouldStartNewBatch = true;
913
} else {
914
+ // This is __EXPENSIVE__.
915
+ // We could end up with hundreds of state updated, and for each one of them
916
+ // would try to create a component stack with possibly hundreds of Fibers.
917
+ // Creating a cache of component stacks won't help, generating a single stack is already expensive enough.
918
+ // We should find a way to lazily generate component stacks on demand, when user inspects a specific event.
919
+ // If we succeed with moving React DevTools Timeline Profiler to Performance panel, then Timeline Profiler would probably be removed.
920
+ // If not, then once enableOwnerStacks is adopted, revisit this again and cache component stacks per Fiber,
921
+ // but only return them when needed, sending hundreds of component stacks is beyond the Bridge's bandwidth.
922
+
923
// Postprocess Profile data
924
if (currentTimelineData !== null) {
925
currentTimelineData.schedulingEvents.forEach(event => {