aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zen/cmds/builds_cmd.cpp40
2 files changed, 35 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a7a24c75..591bd4e81 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@
- Improvement: Skip command line arguments that are empty or just a single space for `zen` command line tool on Mac/Linux to handle "triple space" problem. UE-273411
- Improvement: Extend log information when httpsys response sending fails
- Improvement: Log warning when port remappng occurs due to desired port is already in use
+- Improvement: Custom CopyFile in `zen builds` command increasing throughput by 50% on Windows and give better progress update
## 5.6.7
- Feature: Support for `--log-progress` to output UE style `@progress` log messages has been added to
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++;
}