Skip to content

Commit a5724e5

Browse files
committed
[clang][deps] NFC: Speed up canonical context hash computation
This patch makes use of the infrastructure established in D157046 to speed up computation of the canonical context hash in the dependency scanner. This is somewhat hot code, since it's ran for all modules in the dependency graph of every TU. I also tried an alternative approach that tried to avoid allocations as much as possible (essentially doing `HashBuilder.add(Arg.toStringRef(ArgVec))`), but that turned out to be slower than approach in this patch. Note that this is not problematic in the same way command-line hashing used to be prior D143027. The lambda is now being called even for constant strings. Depends on D157046. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D157052
1 parent ecc4795 commit a5724e5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,13 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
301301
MutableCI.getCASOpts(), {});
302302

303303
// Hash the BuildInvocation without any input files.
304-
SmallVector<const char *, 32> Args;
305-
llvm::BumpPtrAllocator Alloc;
306-
llvm::StringSaver Saver(Alloc);
307-
CI.generateCC1CommandLine(
308-
Args, [&](const Twine &Arg) { return Saver.save(Arg).data(); });
309-
HashBuilder.addRange(Args);
304+
SmallString<0> ArgVec;
305+
ArgVec.reserve(4096);
306+
CI.generateCC1CommandLine([&](const Twine &Arg) {
307+
Arg.toVector(ArgVec);
308+
ArgVec.push_back('\0');
309+
});
310+
HashBuilder.add(ArgVec);
310311

311312
// Hash the module dependencies. These paths may differ even if the invocation
312313
// is identical if they depend on the contents of the files in the TU -- for

0 commit comments

Comments
 (0)