Skip to content

Commit bf2e4a4

Browse files
authored
Defer error chain next_node creation (#191)
Try and optimize arena allloc by deferring it until it is guaranteed to be needed (i.e. since many nodes get pruned by beam, no_revisit_dets, etc. etc. in between) For context, I am hunting down something that looks like a memory leak right now in Tesseract. This popped up as a possible factor but I have not yet measured the impact on memory (or runtime for that matter). But wanted to get advice on it.
1 parent 1e0cd87 commit bf2e4a4

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/tesseract.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,6 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
433433
}
434434
prev_ei = ei;
435435

436-
// Create the error chain node for this candidate.
437-
error_chain_arena.emplace_back();
438-
auto& next_node = error_chain_arena.back();
439-
next_node.error_index = ei;
440-
next_node.min_detector = min_detector;
441-
next_node.parent_idx = node.error_chain_idx;
442-
443436
next_detectors = detectors;
444437
next_detector_cost_tuples[ei].error_blocked = 1;
445438

@@ -483,6 +476,13 @@ void TesseractDecoder::decode_to_errors(const std::vector<uint64_t>& detections,
483476

484477
if (next_cost == INF) continue;
485478

479+
// Create the error chain node for this candidate.
480+
error_chain_arena.emplace_back();
481+
auto& next_node = error_chain_arena.back();
482+
next_node.error_index = ei;
483+
next_node.min_detector = min_detector;
484+
next_node.parent_idx = node.error_chain_idx;
485+
486486
pq.push({next_cost, next_num_dets, node.depth + 1, (int64_t)(error_chain_arena.size() - 1)});
487487
++num_pq_pushed;
488488

0 commit comments

Comments
 (0)