r362584 - Reduce memory consumption of coverage dumps
Serge Guelton via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 4 23:35:11 PDT 2019
Author: serge_sans_paille
Date: Tue Jun 4 23:35:10 2019
New Revision: 362584
URL: http://llvm.org/viewvc/llvm-project?rev=362584&view=rev
Log:
Reduce memory consumption of coverage dumps
Avoiding an intermediate join operation removes the need for an
intermediate buffer that may be quite large, as showcased by
https://bugs.llvm.org/show_bug.cgi?id=41965
Differential Revision: https://reviews.llvm.org/D62623
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=362584&r1=362583&r2=362584&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Tue Jun 4 23:35:10 2019
@@ -1388,10 +1388,19 @@ void CoverageMappingModuleGen::emit() {
std::string FilenamesAndCoverageMappings;
llvm::raw_string_ostream OS(FilenamesAndCoverageMappings);
CoverageFilenamesSectionWriter(FilenameRefs).write(OS);
- std::string RawCoverageMappings =
- llvm::join(CoverageMappings.begin(), CoverageMappings.end(), "");
- OS << RawCoverageMappings;
- size_t CoverageMappingSize = RawCoverageMappings.size();
+
+ // Stream the content of CoverageMappings to OS while keeping
+ // memory consumption under control.
+ size_t CoverageMappingSize = 0;
+ for (auto &S : CoverageMappings) {
+ CoverageMappingSize += S.size();
+ OS << S;
+ S.clear();
+ S.shrink_to_fit();
+ }
+ CoverageMappings.clear();
+ CoverageMappings.shrink_to_fit();
+
size_t FilenamesSize = OS.str().size() - CoverageMappingSize;
// Append extra zeroes if necessary to ensure that the size of the filenames
// and coverage mappings is a multiple of 8.
More information about the cfe-commits
mailing list