Skip to content

Commit 1d402d2

Browse files
[CachedDiagnostics] Optimize in case no diagnostics is emitted
When no diagnostics is emitted from the compilation, just use an empty object as cached diagnostics. That is an optimization for storage to avoid emitting some supporting file to recreate source manager when not needed, also save a bit time from emitting YAML file. rdar://128426132
1 parent 24e5a82 commit 1d402d2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ llvm::Error DiagnosticSerializer::deserializeDiagnosticInfo(
629629

630630
llvm::Error
631631
DiagnosticSerializer::serializeEmittedDiagnostics(llvm::raw_ostream &os) {
632+
// If no diagnostics is produced, do not write anything so output is smaller
633+
// without referencing any files.
634+
if (DiagInfos.empty())
635+
return llvm::Error::success();
636+
632637
// Convert all file backed source file into CASIDs.
633638
for (auto &File : Files) {
634639
if (!File.Content.empty() || !File.ContentCASID.empty())
@@ -822,12 +827,14 @@ CachingDiagnosticsProcessor::CachingDiagnosticsProcessor(
822827

823828
// compress the YAML file.
824829
llvm::SmallVector<uint8_t, 512> Compression;
825-
if (llvm::compression::zstd::isAvailable())
826-
llvm::compression::zstd::compress(arrayRefFromStringRef(Output),
827-
Compression);
828-
else if (llvm::compression::zlib::isAvailable())
829-
llvm::compression::zlib::compress(arrayRefFromStringRef(Output),
830-
Compression);
830+
if (!Output.empty()) {
831+
if (llvm::compression::zstd::isAvailable())
832+
llvm::compression::zstd::compress(arrayRefFromStringRef(Output),
833+
Compression);
834+
else if (llvm::compression::zlib::isAvailable())
835+
llvm::compression::zlib::compress(arrayRefFromStringRef(Output),
836+
Compression);
837+
}
831838

832839
// Write the uncompressed size in the end.
833840
if (!Compression.empty()) {
@@ -872,6 +879,10 @@ llvm::Error CachingDiagnosticsProcessor::serializeEmittedDiagnostics(
872879

873880
llvm::Error
874881
CachingDiagnosticsProcessor::replayCachedDiagnostics(llvm::StringRef Buffer) {
882+
// If empty buffer, no diagnostics to replay.
883+
if (Buffer.empty())
884+
return llvm::Error::success();
885+
875886
SmallVector<uint8_t, 512> Uncompressed;
876887
if (llvm::compression::zstd::isAvailable() ||
877888
llvm::compression::zlib::isAvailable()) {

0 commit comments

Comments
 (0)