From 2d2deecc329c00f1b00f43f11f7d6a517c6d8ec2 Mon Sep 17 00:00:00 2001 From: "Erik Garrison (aider)" Date: Thu, 21 Nov 2024 17:07:26 -0600 Subject: [PATCH] refactor: Move pre-filtering to mapModule to prevent memory buildup --- src/map/include/computeMap.hpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/map/include/computeMap.hpp b/src/map/include/computeMap.hpp index 562713d9..725d4a4c 100644 --- a/src/map/include/computeMap.hpp +++ b/src/map/include/computeMap.hpp @@ -721,21 +721,6 @@ namespace skch aggregator.join(); - // Filter mappings for this subset to reduce memory usage - for (auto& [querySeqId, mappings] : combinedMappings) { - if (param.filterMode == filter::MAP || param.filterMode == filter::ONETOONE) { - MappingResultsVector_t filteredMappings; - filterByGroup(mappings, filteredMappings, param.numMappingsForSegment - 1, false, *idManager, progress); - mappings = std::move(filteredMappings); - - // Also apply length and identity filters - filterWeakMappings(mappings, std::floor(param.block_length / param.segLength)); - if (param.filterLengthMismatches) { - filterFalseHighIdentity(mappings); - } - sparsifyMappings(mappings); - } - } // Reset flags and clear aggregatedMappings for next iteration reader_done.store(false); @@ -956,6 +941,20 @@ namespace skch mappingBoundarySanityCheck(input, output->results); + // Apply pre-filtering immediately after mapping against this subset + if (param.filterMode == filter::MAP || param.filterMode == filter::ONETOONE) { + MappingResultsVector_t filteredMappings; + filterByGroup(output->results, filteredMappings, param.numMappingsForSegment - 1, false, *idManager, input->progress); + output->results = std::move(filteredMappings); + + // Also apply length and identity filters + filterWeakMappings(output->results, std::floor(param.block_length / param.segLength)); + if (param.filterLengthMismatches) { + filterFalseHighIdentity(output->results); + } + sparsifyMappings(output->results); + } + return output; }