Skip to content

Commit

Permalink
Only include commandline flags that contribute to access pattern in c…
Browse files Browse the repository at this point in the history
…ache key.
  • Loading branch information
hzeller committed Jun 4, 2024
1 parent ee11676 commit 351bf77
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions bant/util/filesystem-prewarm-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,23 @@ void FilesystemPrewarmCacheInit(int argc, char *argv[]) {
std::error_code err;
auto cwd = std::filesystem::current_path(err);
uint64_t argument_dependent_hash = std::hash<std::string>()(cwd.string());
for (int i = 0; i < argc; ++i) {
argument_dependent_hash ^= std::hash<std::string_view>()(argv[i]);
for (int i = 1; i < argc; ++i) {
const std::string_view arg(argv[i]);
// With or without the following flags, same access pattern expected; don't
// inlude them in the cache uniqifier.
if (arg == "-v" || arg == "-k" || arg == "-q") continue;

if (arg == "-C" || // already reflected in the cwd
arg == "-o" || arg == "-f") {
++i; // Skip optarg
continue;
}

argument_dependent_hash ^= std::hash<std::string_view>()(arg);
}

const std::string cache_file = absl::StrFormat(
"%s/fswarm-%08x", cache_dir, argument_dependent_hash & 0xffff'ffff);
"%s/fs-warm-%08x", cache_dir, argument_dependent_hash & 0xffff'ffff);
FilesystemPrewarmCache::instance().InitCacheFile(cache_file);
}

Expand Down

0 comments on commit 351bf77

Please sign in to comment.