[PATCH] D147960: [lld-macho] Cache discovered dylib paths
Keith Smiley via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 12:16:10 PDT 2023
keith created this revision.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In cases where you have many dylibs referenced by load commands, this
would be accessed repeated times for the same dylibs causing huge time
spikes.
Fixes https://github.com/keith/rules_apple_linker/issues/38
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147960
Files:
lld/MachO/DriverUtils.cpp
Index: lld/MachO/DriverUtils.cpp
===================================================================
--- lld/MachO/DriverUtils.cpp
+++ lld/MachO/DriverUtils.cpp
@@ -186,20 +186,32 @@
depTracker->logFileNotFound(path);
}
+static DenseMap<CachedHashStringRef, StringRef> resolvedDylibs;
std::optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
+ CachedHashStringRef key(dylibPath);
+ auto entry = resolvedDylibs.find(key);
+ if (entry != resolvedDylibs.end())
+ return entry->second;
+
// TODO: if a tbd and dylib are both present, we should check to make sure
// they are consistent.
SmallString<261> tbdPath = dylibPath;
path::replace_extension(tbdPath, ".tbd");
bool tbdExists = fs::exists(tbdPath);
searchedDylib(tbdPath, tbdExists);
- if (tbdExists)
- return saver().save(tbdPath.str());
+ if (tbdExists) {
+ StringRef file = saver().save(tbdPath.str());
+ resolvedDylibs[key] = file;
+ return file;
+ }
bool dylibExists = fs::exists(dylibPath);
searchedDylib(dylibPath, dylibExists);
- if (dylibExists)
- return saver().save(dylibPath);
+ if (dylibExists) {
+ StringRef file = saver().save(dylibPath);
+ resolvedDylibs[key] = file;
+ return file;
+ }
return {};
}
@@ -253,7 +265,10 @@
return newFile;
}
-void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
+void macho::resetLoadedDylibs() {
+ resolvedDylibs.clear();
+ loadedDylibs.clear();
+}
std::optional<StringRef>
macho::findPathCombination(const Twine &name,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147960.512215.patch
Type: text/x-patch
Size: 1529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230410/ee7d11d3/attachment.bin>
More information about the llvm-commits
mailing list