@samitouri / QOS-React / commits / 1846d4fe59

Fixed a bug where treeBaseDurations were undefined for fibers that were unmounted during profiling

Brian Vaughn committed Mar 19, 2019 at 11:08 UTC 1846d4fe5907ee17434b65f68ea8986129d96c8b
1 file changed +12 -2
src/backend/renderer.js
+12 -2
@@ -592,6 +592,7 @@ export function attach(
592
593 const ownerID =
594 _debugOwner != null ? getFiberID(getPrimaryFiber(_debugOwner)) : 0;
595 + const parentID = getFiberID(getPrimaryFiber(parentFiber));
596
597 let encodedDisplayName = ((null: any): Uint8Array);
598 let encodedKey = ((null: any): Uint8Array);
@@ -617,7 +618,7 @@ export function attach(
618 operation[0] = TREE_OPERATION_ADD;
619 operation[1] = id;
620 operation[2] = type;
620 - operation[3] = getFiberID(getPrimaryFiber(parentFiber));
621 + operation[3] = parentID;
622 operation[4] = ownerID;
623 operation[5] = encodedDisplayNameSize;
624 if (displayName !== null) {
@@ -1398,6 +1399,7 @@ export function attach(
1399
1400 let currentCommitProfilingMetadata: CommitProfilingData | null = null;
1401 let initialTreeBaseDurationsMap: Map<number, number> | null = null;
1402 + let initialIDToRootMap: Map<number, number> | null = null;
1403 let isProfiling: boolean = false;
1404 let profilingStartTime: number = 0;
1405 let rootToCommitProfilingMetadataMap: CommitProfilingMetadataMap | null = null;
@@ -1450,7 +1452,9 @@ export function attach(
1452 const initialTreeBaseDurations = [];
1453 ((initialTreeBaseDurationsMap: any): Map<number, number>).forEach(
1454 (treeBaseDuration, id) => {
1453 - if (idToRootMap.get(id) === rootID) {
1455 + if (
1456 + ((initialIDToRootMap: any): Map<number, number>).get(id) === rootID
1457 + ) {
1458 // We don't need to convert milliseconds to microseconds in this case,
1459 // because the profiling summary is JSON serialized.
1460 initialTreeBaseDurations.push(id, treeBaseDuration);
@@ -1468,7 +1472,13 @@ export function attach(
1472 }
1473
1474 function startProfiling() {
1475 + // Capture initial values as of the time profiling starts.
1476 + // It's important we snapshot both the durations and the id-to-root map,
1477 + // since either of these may change during the profiling session
1478 + // (e.g. when a fiber is re-rendered or when a fiber gets removed).
1479 initialTreeBaseDurationsMap = new Map(idToTreeBaseDurationMap);
1480 + initialIDToRootMap = new Map(idToRootMap);
1481 +
1482 isProfiling = true;
1483 profilingStartTime = performance.now();
1484 rootToCommitProfilingMetadataMap = new Map();