aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-05-20 16:28:17 +0200
committerGitHub Enterprise <[email protected]>2025-05-20 16:28:17 +0200
commit91515f65aec01f99931cc2b774fdb533f308d206 (patch)
treedb12caf52e54e6993e4c43508ffdb124ab7519bc /src
parenthandle exception with batch work (#401) (diff)
downloadzen-91515f65aec01f99931cc2b774fdb533f308d206.tar.xz
zen-91515f65aec01f99931cc2b774fdb533f308d206.zip
replace copy file (#403)
Custom CopyFile in zen builds command increasing throughput by 50% on Windows and give better progress update
Diffstat (limited to 'src')
-rw-r--r--src/zen/cmds/builds_cmd.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/zen/cmds/builds_cmd.cpp b/src/zen/cmds/builds_cmd.cpp
index 78d362fdb..1a570d6da 100644
--- a/src/zen/cmds/builds_cmd.cpp
+++ b/src/zen/cmds/builds_cmd.cpp
@@ -304,6 +304,26 @@ namespace {
}
}
+ void CopyFile(const std::filesystem::path& SourceFilePath,
+ const std::filesystem::path& TargetFilePath,
+ uint64_t RawSize,
+ std::atomic<uint64_t>& WriteCount,
+ std::atomic<uint64_t>& WriteByteCount)
+ {
+ BasicFile TargetFile(TargetFilePath, BasicFile::Mode::kTruncate);
+ PrepareFileForScatteredWrite(TargetFile.Handle(), RawSize);
+ uint64_t Offset = 0;
+ if (!ScanFile(SourceFilePath, 512u * 1024u, [&](const void* Data, size_t Size) {
+ TargetFile.Write(Data, Size, Offset);
+ Offset += Size;
+ WriteCount++;
+ WriteByteCount += Size;
+ }))
+ {
+ throw std::runtime_error(fmt::format("Failed to copy scavanged file '{}' to '{}'", SourceFilePath, TargetFilePath));
+ }
+ }
+
uint32_t SetNativeFileAttributes(const std::filesystem::path FilePath, SourcePlatform SourcePlatform, uint32_t Attributes)
{
#if ZEN_PLATFORM_WINDOWS
@@ -6198,6 +6218,10 @@ namespace {
Work.ScheduleWork(WritePool, [&, ScavengeOpIndex](std::atomic<bool>&) mutable {
if (!AbortFlag)
{
+ ZEN_TRACE_CPU("UpdateFolder_WriteScavanged");
+
+ FilteredWrittenBytesPerSecond.Start();
+
const ScavengeCopyOperation& ScavengeOp = ScavengeCopyOperations[ScavengeOpIndex];
const ChunkedFolderContent& ScavengedContent = ScavengedContents[ScavengeOp.ScavengedContentIndex];
const std::filesystem::path ScavengedPath = ScavengedContent.Paths[ScavengeOp.ScavengedPathIndex];
@@ -6211,10 +6235,8 @@ namespace {
const std::filesystem::path TempFilePath =
GetTempChunkedSequenceFileName(CacheFolderPath, RemoteSequenceRawHash);
- CopyFile(ScavengedFilePath, TempFilePath, {.EnableClone = false});
-
- DiskStats.WriteCount++;
- DiskStats.WriteByteCount += ScavengeOp.RawSize;
+ const uint64_t RawSize = ScavengedContent.RawSizes[ScavengeOp.ScavengedContentIndex];
+ CopyFile(ScavengedFilePath, TempFilePath, RawSize, DiskStats.WriteCount, DiskStats.WriteByteCount);
const std::filesystem::path CacheFilePath =
GetFinalChunkedSequenceFileName(CacheFolderPath, RemoteSequenceRawHash);
@@ -7527,7 +7549,10 @@ namespace {
ZEN_ASSERT_SLOW(IsFileWithRetry(SourceFilePath));
ZEN_DEBUG("Copying from '{}' -> '{}'", SourceFilePath, FirstTargetFilePath);
- CopyFile(SourceFilePath, FirstTargetFilePath, {.EnableClone = false});
+ const uint64_t RawSize = LocalContent.RawSizes[LocalPathIndex];
+ std::atomic<uint64_t> WriteCount;
+ std::atomic<uint64_t> WriteByteCount;
+ CopyFile(SourceFilePath, FirstTargetFilePath, RawSize, WriteCount, WriteByteCount);
RebuildFolderStateStats.FinalizeTreeFilesCopiedCount++;
}
else
@@ -7581,7 +7606,10 @@ namespace {
ZEN_ASSERT_SLOW(IsFileWithRetry(FirstTargetFilePath));
ZEN_DEBUG("Copying from '{}' -> '{}'", FirstTargetFilePath, TargetFilePath);
- CopyFile(FirstTargetFilePath, TargetFilePath, {.EnableClone = false});
+ const uint64_t RawSize = RemoteContent.RawSizes[RemotePathIndex];
+ std::atomic<uint64_t> WriteCount;
+ std::atomic<uint64_t> WriteByteCount;
+ CopyFile(FirstTargetFilePath, TargetFilePath, RawSize, WriteCount, WriteByteCount);
RebuildFolderStateStats.FinalizeTreeFilesCopiedCount++;
}