@samitouri / QOS-React / commits / f4b3a1fea2

[DevTools] Delete fiberToFiberInstanceMap (#30900)

Stacked on #30899. After the rest of the stack this is now unused so we can save time and memory avoiding to maintain it. 🎉

Sebastian Markbåge committed Sep 9, 2024 at 15:12 UTC f4b3a1fea2485c414985d341d6445660da471a98
1 file changed +1 -43
packages/react-devtools-shared/src/backend/fiber/renderer.js
+1 -43
@@ -744,13 +744,7 @@ const knownEnvironmentNames: Set<string> = new Set();
744 // Map of FiberRoot to their root FiberInstance.
745 const rootToFiberInstanceMap: Map<FiberRoot, FiberInstance> = new Map();
746
747 -// Map of one or more Fibers in a pair to their unique id number.
748 -// We track both Fibers to support Fast Refresh,
749 -// which may forcefully replace one of the pair as part of hot reloading.
750 -// In that case it's still important to be able to locate the previous ID during subsequent renders.
751 -const fiberToFiberInstanceMap: Map<Fiber, FiberInstance> = new Map();
752 -
753 -// Map of id to one (arbitrary) Fiber in a pair.
747 +// Map of id to FiberInstance or VirtualInstance.
748 // This Map is used to e.g. get the display name for a Fiber or schedule an update,
749 // operations that should be the same whether the current and work-in-progress Fiber is used.
750 const idToDevToolsInstanceMap: Map<number, FiberInstance | VirtualInstance> =
@@ -1327,14 +1321,9 @@ export function attach(
1321 // Recursively re-mount all roots with new filter criteria applied.
1322 hook.getFiberRoots(rendererID).forEach(root => {
1323 const current = root.current;
1330 - const alternate = current.alternate;
1324 const newRoot = createFiberInstance(current);
1325 rootToFiberInstanceMap.set(root, newRoot);
1326 idToDevToolsInstanceMap.set(newRoot.id, newRoot);
1334 - fiberToFiberInstanceMap.set(current, newRoot);
1335 - if (alternate) {
1336 - fiberToFiberInstanceMap.set(alternate, newRoot);
1337 - }
1327
1328 // Before the traversals, remember to start tracking
1329 // our path in case we have selection to restore.
@@ -2016,14 +2005,6 @@ export function attach(
2005 } else {
2006 fiberInstance = createFiberInstance(fiber);
2007 }
2019 - // If this already exists behind a different FiberInstance, we intentionally
2020 - // override it here to claim the fiber as part of this new instance.
2021 - // E.g. if it was part of a reparenting.
2022 - fiberToFiberInstanceMap.set(fiber, fiberInstance);
2023 - const alternate = fiber.alternate;
2024 - if (alternate !== null && fiberToFiberInstanceMap.has(alternate)) {
2025 - fiberToFiberInstanceMap.set(alternate, fiberInstance);
2026 - }
2008 idToDevToolsInstanceMap.set(fiberInstance.id, fiberInstance);
2009
2010 const id = fiberInstance.id;
@@ -2237,16 +2218,6 @@ export function attach(
2218
2219 idToDevToolsInstanceMap.delete(fiberInstance.id);
2220
2240 - if (fiberToFiberInstanceMap.get(fiber) === fiberInstance) {
2241 - fiberToFiberInstanceMap.delete(fiber);
2242 - }
2243 - const {alternate} = fiber;
2244 - if (alternate !== null) {
2245 - if (fiberToFiberInstanceMap.get(alternate) === fiberInstance) {
2246 - fiberToFiberInstanceMap.delete(alternate);
2247 - }
2248 - }
2249 -
2221 untrackFiber(fiberInstance, fiber);
2222 }
2223
@@ -3084,9 +3055,6 @@ export function attach(
3055 shouldResetChildren = true;
3056 }
3057
3087 - // Register the new alternate in case it's not already in.
3088 - fiberToFiberInstanceMap.set(nextChild, fiberInstance);
3089 -
3058 moveChild(fiberInstance, previousSiblingOfExistingInstance);
3059
3060 if (
@@ -3467,11 +3435,6 @@ export function attach(
3435 const newRoot = createFiberInstance(current);
3436 rootToFiberInstanceMap.set(root, newRoot);
3437 idToDevToolsInstanceMap.set(newRoot.id, newRoot);
3470 - fiberToFiberInstanceMap.set(current, newRoot);
3471 - const alternate = current.alternate;
3472 - if (alternate) {
3473 - fiberToFiberInstanceMap.set(alternate, newRoot);
3474 - }
3438 currentRoot = newRoot;
3439 setRootPseudoKey(currentRoot.id, root.current);
3440
@@ -3541,11 +3504,6 @@ export function attach(
3504 rootInstance = createFiberInstance(current);
3505 rootToFiberInstanceMap.set(root, rootInstance);
3506 idToDevToolsInstanceMap.set(rootInstance.id, rootInstance);
3544 - fiberToFiberInstanceMap.set(current, rootInstance);
3545 - const alternate = current.alternate;
3546 - if (alternate) {
3547 - fiberToFiberInstanceMap.set(alternate, rootInstance);
3548 - }
3507 } else {
3508 prevFiber = rootInstance.data;
3509 }