Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix severe perf problems in component tree devtool #6770

Merged
merged 1 commit into from
May 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/isomorphic/devtools/ReactComponentTreeDevtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
var invariant = require('invariant');

var tree = {};
var rootIDs = [];
var unmountedIDs = {};
var rootIDs = {};

function updateTree(id, update) {
if (!tree[id]) {
Expand All @@ -27,6 +28,10 @@ function updateTree(id, update) {
isMounted: false,
updateCount: 0,
};
// TODO: We need to do this awkward dance because TopLevelWrapper "never
// gets mounted" but its display name gets set in instantiateReactComponent
// before its debug ID is set to 0.
unmountedIDs[id] = true;
}
update(tree[id]);
}
Expand Down Expand Up @@ -90,10 +95,11 @@ var ReactComponentTreeDevtool = {

onMountComponent(id) {
updateTree(id, item => item.isMounted = true);
delete unmountedIDs[id];
},

onMountRootComponent(id) {
rootIDs.push(id);
rootIDs[id] = true;
},

onUpdateComponent(id) {
Expand All @@ -102,7 +108,8 @@ var ReactComponentTreeDevtool = {

onUnmountComponent(id) {
updateTree(id, item => item.isMounted = false);
rootIDs = rootIDs.filter(rootID => rootID !== id);
unmountedIDs[id] = true;
delete rootIDs[id];
},

purgeUnmountedComponents() {
Expand All @@ -111,9 +118,10 @@ var ReactComponentTreeDevtool = {
return;
}

Object.keys(tree)
.filter(id => !tree[id].isMounted)
.forEach(purgeDeep);
for (var id in unmountedIDs) {
purgeDeep(id);
}
unmountedIDs = {};
},

isMounted(id) {
Expand Down Expand Up @@ -152,7 +160,7 @@ var ReactComponentTreeDevtool = {
},

getRootIDs() {
return rootIDs;
return Object.keys(rootIDs);
},

getRegisteredIDs() {
Expand Down