diff options
author | Benoit Steiner <bsteiner@google.com> | 2017-08-17 15:50:02 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-08-17 15:53:52 -0700 |
commit | 30998218b97da9c951ea41a3b03273f2cf75a88e (patch) | |
tree | 140cbed57f261228256a0daea83ad66b4eaaa412 /tensorflow/core/graph/graph.cc | |
parent | 2f55234e42ab7ed13dc0e09284d2691f64e8f7e2 (diff) |
Speed up the graph to graphdef conversion
PiperOrigin-RevId: 165640923
Diffstat (limited to 'tensorflow/core/graph/graph.cc')
-rw-r--r-- | tensorflow/core/graph/graph.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc index 07518ee341..241e093eea 100644 --- a/tensorflow/core/graph/graph.cc +++ b/tensorflow/core/graph/graph.cc @@ -444,6 +444,9 @@ void Graph::ToGraphDefSubRange(GraphDef* graph_def, int from_node_id) const { graph_def->Clear(); *graph_def->mutable_versions() = versions(); *graph_def->mutable_library() = ops_.ToProto(); + + graph_def->mutable_node()->Reserve(std::max(1, num_nodes() - from_node_id)); + std::vector<const Edge*> inputs; // Construct this outside the loop for speed. for (auto id = from_node_id; id < num_node_ids(); ++id) { @@ -477,6 +480,8 @@ void Graph::ToGraphDefSubRange(GraphDef* graph_def, int from_node_id) const { } } node_def->clear_input(); + node_def->mutable_input()->Reserve(inputs.size()); + for (size_t i = 0; i < inputs.size(); ++i) { const Edge* edge = inputs[i]; if (edge == nullptr) { |