BullDemonKing commented on a change in pull request #13588: Accelerate DGL csr neighbor sampling URL: https://github.com/apache/incubator-mxnet/pull/13588#discussion_r242011871
########## File path: src/operator/contrib/dgl_graph.cc ########## @@ -586,123 +563,119 @@ static void SampleSubgraph(const NDArray &csr, dgl_id_t* out_layer = sub_layer.data().dptr<dgl_id_t>(); // BFS traverse the graph and sample vertices - dgl_id_t sub_vertices_count = 0; // <vertex_id, layer_id> - std::unordered_map<dgl_id_t, int> sub_ver_mp; - std::queue<ver_node> node_queue; + std::unordered_set<dgl_id_t> sub_ver_mp; + std::vector<std::pair<dgl_id_t, dgl_id_t> > sub_vers; + sub_vers.reserve(num_seeds * 10); Review comment: This number is used for reserving memory, so it doesn't have to be very accurate. The goal here is to balance memory reallocation and memory consumption in std::vector. If num_hop is 1, 10 might be good enough; if num_hop is 2, 10 will be too small. But I don't feel that we need to make it overcomplex. After all, we only want to reduce the overhead of memory reallocation in std::vector. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
