Skip to content

Commit

Permalink
Add little more clarity into the way numParallelFileReads is defined …
Browse files Browse the repository at this point in the history
…inside CArchiveScanner::GetArchiveChecksum, also use 1 thread to read from a spinning disk drive's directory and compressed archives
  • Loading branch information
lhog committed Jan 1, 2025
1 parent 8019af9 commit cb7d31c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions rts/System/FileSystem/ArchiveScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,24 @@ IFileFilter* CArchiveScanner::CreateIgnoreFilter(IArchive* ar)
bool CArchiveScanner::GetArchiveChecksum(const std::string& archiveName, ArchiveInfo& archiveInfo)
{
// try to open an archive
bool isOnSpinningDisk = FileSystem::IsPathOnSpinningDisk(archiveName);
std::unique_ptr<IArchive> ar(archiveLoader.OpenArchive(archiveName));

if (ar == nullptr)
return false;

int numParallelFileReads = 1; // compressed archives have a mutex, can't read files in parallel

if (ar->GetType() == ARCHIVE_TYPE_SDD) {
if (bool isOnSpinningDisk = FileSystem::IsPathOnSpinningDisk(archiveName); isOnSpinningDisk) {
// decrease spinning disk thrashing, read using one thread only
numParallelFileReads = 1;
} else {
numParallelFileReads = ThreadPool::GetNumThreads();
}
}

numParallelFileReads = std::max(numParallelFileReads, 1);

// load ignore list, and insert all files to check in lowercase format
std::unique_ptr<IFileFilter> ignore(CreateIgnoreFilter(ar.get()));
std::vector<std::string> fileNames;
Expand Down Expand Up @@ -987,8 +999,6 @@ bool CArchiveScanner::GetArchiveChecksum(const std::string& archiveName, Archive
std::vector<std::shared_ptr<std::future<void>>> tasks;
tasks.reserve(fileNames.size());

// decrease spinning disk thrashing a little bit.
const auto numParallelFileReads = std::max(isOnSpinningDisk ? ThreadPool::GetNumThreads() >> 1 : ThreadPool::GetNumThreads(), 1);
std::counting_semaphore sem(numParallelFileReads);

auto ComputeHashesTask = [&ar, &fileNames, &fileHashes, &sem, this](size_t fidx) -> void {
Expand Down

0 comments on commit cb7d31c

Please sign in to comment.