[Serialization] Reduce file size by splitting dep dirnames from basenames

Dependency tracking for cached compiled modules (compiled from
swiftinterfaces) can lead to a high percentage of the module being
SDK-relative paths when -track-system-dependencies is on. Cut down on
this by storing directory names in a separate record that gets
referenced from each file dependency. (Since a lot of per-file
dependencies are header files in a common directory, this is a win.)

We can do something more clever in the future, but this is a
reasonable start for, say, the overlays.

rdar://problem/50449802
This commit is contained in:
Jordan Rose
2019-05-04 10:42:44 -07:00
parent 9ba1d8a1c6
commit b3c5a68acf
4 changed files with 48 additions and 4 deletions

View File

@@ -239,6 +239,9 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
static bool validateInputBlock(
llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t> &scratch,
SmallVectorImpl<SerializationOptions::FileDependency> &dependencies) {
SmallVector<StringRef, 4> dependencyDirectories;
SmallString<256> dependencyFullPathBuffer;
while (!cursor.AtEndOfStream()) {
auto entry = cursor.advance();
if (entry.Kind == llvm::BitstreamEntry::EndBlock)
@@ -255,17 +258,30 @@ static bool validateInputBlock(
bool isHashBased = scratch[2] != 0;
bool isSDKRelative = scratch[3] != 0;
StringRef path = blobData;
size_t directoryIndex = scratch[4];
if (directoryIndex != 0) {
if (directoryIndex > dependencyDirectories.size())
return true;
dependencyFullPathBuffer = dependencyDirectories[directoryIndex-1];
llvm::sys::path::append(dependencyFullPathBuffer, blobData);
path = dependencyFullPathBuffer;
}
if (isHashBased) {
dependencies.push_back(
SerializationOptions::FileDependency::hashBased(
blobData, isSDKRelative, scratch[0], scratch[1]));
path, isSDKRelative, scratch[0], scratch[1]));
} else {
dependencies.push_back(
SerializationOptions::FileDependency::modTimeBased(
blobData, isSDKRelative, scratch[0], scratch[1]));
path, isSDKRelative, scratch[0], scratch[1]));
}
break;
}
case input_block::DEPENDENCY_DIRECTORY:
dependencyDirectories.push_back(blobData);
break;
default:
// Unknown metadata record, possibly for use by a future version of the
// module format.