Skip to content

Commit

Permalink
Reduce memory consumption of coverage dumps
Browse files Browse the repository at this point in the history
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

llvm-svn: 362584
  • Loading branch information
Serge Guelton committed Jun 5, 2019
1 parent a3e1671 commit 4cd07db
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Expand Up @@ -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.
Expand Down

0 comments on commit 4cd07db

Please sign in to comment.