versioner: use a virtual filesystem for input files.
Use an InMemoryFileSystem to store and share input files across
compilations.
This improves the result of `time versioner` further, from:
versioner 109.12s user 17.43s system 2433% cpu 5.201 total
to:
versioner 112.20s user 1.38s system 2416% cpu 4.700 total
Bug: http://b/32748936
Test: python run_tests.py
Change-Id: I72d37b7c30850b8399cc40338247700fe3e7b2f9
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index f0a2339..5aaf47a 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -44,6 +44,8 @@
#include "Preprocessor.h"
#include "SymbolDatabase.h"
#include "Utils.h"
+#include "VFS.h"
+
#include "versioner.h"
using namespace std::string_literals;
@@ -138,6 +140,8 @@
errx(1, "compileHeaders received no CompilationTypes");
}
+ auto vfs = createCommonVFS(header_dir, dependency_dir, add_include);
+
size_t thread_count = max_thread_count;
std::vector<std::thread> threads;
@@ -151,7 +155,7 @@
}
}
- initializeTargetCC1FlagCache(types, requirements);
+ initializeTargetCC1FlagCache(vfs, types, requirements);
std::vector<std::pair<CompilationType, const std::string&>> jobs;
for (CompilationType type : types) {
@@ -165,16 +169,16 @@
if (thread_count == 1) {
for (const auto& job : jobs) {
- compileHeader(result.get(), job.first, job.second);
+ compileHeader(vfs, result.get(), job.first, job.second);
}
} else {
// Spawn threads.
for (size_t i = 0; i < thread_count; ++i) {
- threads.emplace_back([&jobs, &result, &header_dir, thread_count, i]() {
+ threads.emplace_back([&jobs, &result, &header_dir, vfs, thread_count, i]() {
size_t index = i;
while (index < jobs.size()) {
const auto& job = jobs[index];
- compileHeader(result.get(), job.first, job.second);
+ compileHeader(vfs, result.get(), job.first, job.second);
index += thread_count;
}
});