aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-06-25 04:12:13 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-25 04:13:35 -0700
commitf5043d6831ea1c266104363b4e8911eb97f96fbc (patch)
tree476c881f074d9200ab28ab611fc41740525b2534 /src/main/cpp
parentb60215b6a97bd60ff000e1bfd9b29a467154d8e2 (diff)
Windows,client: extract embedded binaries faster
When extracting embedded binaries, the client now caches which directories it has already created and won't attempt creating them again. This saves some time on Windows: from 16.3 sec on average down to 13.2 sec. (n=10 runs, always starting Bazel with a new --output_user_root and shutting down afterwards.) On Linux I see only a marginal speedup, not significant enough to claim credit for it. :) See https://github.com/bazelbuild/bazel/issues/5444 Closes #5448. PiperOrigin-RevId: 201933181
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/blaze.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 5073fe513c..eb72cb5263 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -893,9 +893,15 @@ class ExtractBlazeZipProcessor : public PureZipExtractorProcessor {
void Process(const char *filename, const devtools_ijar::u4 attr,
const devtools_ijar::u1 *data, const size_t size) override {
string path = blaze_util::JoinPath(embedded_binaries_, filename);
- if (!blaze_util::MakeDirectories(blaze_util::Dirname(path), 0777)) {
- BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
- << "couldn't create '" << path << "': " << GetLastErrorString();
+ // Performance optimization: memoize the paths we already created a
+ // directory for, to spare a stat in attempting to recreate an already
+ // existing directory. This optimization alone shaves off seconds from the
+ // extraction time on Windows.
+ if (created_directories_.insert(path).second) {
+ if (!blaze_util::MakeDirectories(blaze_util::Dirname(path), 0777)) {
+ BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
+ << "couldn't create '" << path << "': " << GetLastErrorString();
+ }
}
if (!blaze_util::WriteFile(data, size, path, 0755)) {
@@ -907,6 +913,7 @@ class ExtractBlazeZipProcessor : public PureZipExtractorProcessor {
private:
const string embedded_binaries_;
+ set<string> created_directories_;
};
// Actually extracts the embedded data files into the tree whose root