public void reuseNodes(ComponentGraph old) {
        //  copy instances if node equal
        Set<ComponentId> commonComponentIds = Sets.intersection(nodesById.keySet(), old.nodesById.keySet());
        for (ComponentId id : commonComponentIds) {
            if (nodesById.get(id).equals(old.nodesById.get(id))) {
                nodesById.get(id).instance = old.nodesById.get(id).instance;
            }
        }

        // reset instances with modified dependencies
        for (Node node : topologicalSort(nodes())) {
            for (Node usedComponent : node.usedComponents()) {
                if (usedComponent.instance.isEmpty()) {
                    node.instance = Optional.empty();
                }
            }
        }
    }
@author Tony Vaagenes
@author gjoranv
@author ollivir

Not thread safe.
container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentGraph.java