Skip to content

Commit 0af2cb0

Browse files
LHT129opencode
andcommitted
perf: use const reference in ConjugateGraph::Serialize loop to avoid unnecessary copies
Replace value copy with const reference for both the map entry and the dereferenced UnorderedSet in the Serialize loop. This eliminates N atomic shared_ptr increments and N full UnorderedSet copies when serializing a conjugate graph with N nodes. Signed-off-by: tianlan.lht <tianlan.lht@antgroup.com> Co-authored-by: opencode <opencode@anthropic.com> Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
1 parent 3b19c17 commit 0af2cb0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/impl/conjugate_graph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ tl::expected<void, Error>
155155
ConjugateGraph::Serialize(std::ostream& out_stream) const {
156156
out_stream.write((char*)&memory_usage_, sizeof(memory_usage_));
157157

158-
for (auto item : conjugate_graph_) {
159-
auto neighbor_set = *item.second;
158+
for (const auto& item : conjugate_graph_) {
159+
const auto& neighbor_set = *item.second;
160160
uint64_t neighbor_set_size = neighbor_set.size();
161161

162162
out_stream.write((char*)&item.first, sizeof(item.first));

0 commit comments

Comments
 (0)