Skip to content

Commit

Permalink
Windows,client: extract embedded binaries faster
Browse files Browse the repository at this point in the history
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 bazelbuild#5444
  • Loading branch information
laszlocsomor committed Jun 22, 2018
1 parent bda12a1 commit 1fe97d6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/cpp/blaze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down

0 comments on commit 1fe97d6

Please sign in to comment.