最適化: NTFS MFT走査およびディスク読み取りの並列化と限界高速化
- 複数ドライブ(C:, Z:等)のMFTスキャンを完全並列実行するように改善 - MFTのI/Oバッファを2MBに拡張しシステムコールを削減 - ターゲット外ファイルの無駄な文字列化・オブジェクト生成を完全スキップする2パス抽出アルゴリズムを導入 - 既存ゲーム実在検証処理(VerifyAndEnrichGamesAsync)をParallel.ForEachで並列化 - 新規フォルダ走査の並列度引き上げと複数ドライブ同時走査に対応
This commit is contained in:
1 parent
dd00c96e20
commit
b0fdea2411
3 files changed
+252
-125
No files matched your search
@@ -610,26 +610,39 @@ namespace GameLauncher.Services
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var copyList = games.ToList();
|
||||
bool cacheNeedsSave = false;
|
||||
int cacheNeedsSave = 0;
|
||||
|
||||
int total = copyList.Count;
|
||||
int processed = 0;
|
||||
|
||||
foreach (var game in copyList)
|
||||
var po = new ParallelOptions
|
||||
{
|
||||
processed++;
|
||||
if (onProgress != null && (processed % 5 == 0 || processed == total))
|
||||
CancellationToken = ct,
|
||||
MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount * 2, 4, 16)
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(copyList, po, (game, loopState) =>
|
||||
{
|
||||
onProgress(processed, total, $"実在検証中... ({processed}/{total})");
|
||||
}
|
||||
if (ct.IsCancellationRequested) break;
|
||||
if (ct.IsCancellationRequested)
|
||||
{
|
||||
loopState.Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
int current = Interlocked.Increment(ref processed);
|
||||
if (onProgress != null && (current % 10 == 0 || current == total))
|
||||
{
|
||||
onProgress(current, total, $"実在検証中... ({current}/{total})");
|
||||
}
|
||||
|
||||
// 実在検証
|
||||
if (!Directory.Exists(game.RootDirectory))
|
||||
{
|
||||
onGameRemoved(game);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (game is UnityGameItem ug)
|
||||
@@ -640,13 +653,13 @@ namespace GameLauncher.Services
|
||||
if (!string.IsNullOrEmpty(recovered))
|
||||
{
|
||||
ug.ExecutablePath = recovered;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
onGameRemoved(ug);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,7 +669,7 @@ namespace GameLauncher.Services
|
||||
try
|
||||
{
|
||||
ug.FolderLastModified = Directory.GetLastWriteTime(ug.RootDirectory);
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -666,7 +679,7 @@ namespace GameLauncher.Services
|
||||
if (ug.HasSaveData != hasSave)
|
||||
{
|
||||
ug.HasSaveData = hasSave;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
|
||||
// アイコン読み込み
|
||||
@@ -692,7 +705,7 @@ namespace GameLauncher.Services
|
||||
tg.RgssArchivePath = null;
|
||||
tg.PluginsJsPath = string.Empty;
|
||||
tg.PluginsDirPath = string.Empty;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
|
||||
@@ -704,7 +717,7 @@ namespace GameLauncher.Services
|
||||
FixRgssTitleFromIni(tg);
|
||||
if (tg.Title != oldTitle)
|
||||
{
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
}
|
||||
@@ -727,7 +740,7 @@ namespace GameLauncher.Services
|
||||
{
|
||||
tg.EvbExtractedDirPath = currentEvbOutDir;
|
||||
}
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
|
||||
@@ -740,13 +753,13 @@ namespace GameLauncher.Services
|
||||
if (!string.IsNullOrEmpty(recovered))
|
||||
{
|
||||
tg.ExecutablePath = recovered;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,7 +776,7 @@ namespace GameLauncher.Services
|
||||
tg.IsWolfExtracted = isWolfExtracted;
|
||||
tg.WolfProxyDll = isProxyDll;
|
||||
tg.IsModded = isProxyDll;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
}
|
||||
else if (tg.IsSrpgStudio)
|
||||
@@ -774,13 +787,13 @@ namespace GameLauncher.Services
|
||||
if (!string.IsNullOrEmpty(recovered))
|
||||
{
|
||||
tg.ExecutablePath = recovered;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,7 +810,7 @@ namespace GameLauncher.Services
|
||||
tg.IsSrpgExtracted = isSrpgExtracted;
|
||||
tg.SrpgProxyDll = isProxyDll;
|
||||
tg.IsModded = isProxyDll || isModScript;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
}
|
||||
else if (tg.IsAsar)
|
||||
@@ -808,8 +821,8 @@ namespace GameLauncher.Services
|
||||
if (!asarExists)
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// 解凍状態の整合性確認
|
||||
@@ -819,13 +832,13 @@ namespace GameLauncher.Services
|
||||
if (tg.IsAsarExtracted && (!dirExtracted || !jsExists))
|
||||
{
|
||||
tg.IsAsarExtracted = false;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
else if (!tg.IsAsarExtracted && dirExtracted && jsExists)
|
||||
{
|
||||
tg.IsAsarExtracted = true;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
}
|
||||
@@ -837,14 +850,14 @@ namespace GameLauncher.Services
|
||||
if (!archiveExists && !scriptExists)
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tg.IsRgssExtracted != scriptExists)
|
||||
{
|
||||
tg.IsRgssExtracted = scriptExists;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
}
|
||||
@@ -853,8 +866,8 @@ namespace GameLauncher.Services
|
||||
if (!File.Exists(tg.ExecutablePath) && !File.Exists(Path.Combine(tg.RootDirectory, "package.json")))
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (tg.IsEvbPacked || tg.IsStandaloneExePackage || tg.IsOther)
|
||||
@@ -865,13 +878,13 @@ namespace GameLauncher.Services
|
||||
if (!string.IsNullOrEmpty(recovered))
|
||||
{
|
||||
tg.ExecutablePath = recovered;
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -880,8 +893,8 @@ namespace GameLauncher.Services
|
||||
if (!File.Exists(tg.PluginsJsPath))
|
||||
{
|
||||
onGameRemoved(tg);
|
||||
cacheNeedsSave = true;
|
||||
continue;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,7 +904,7 @@ namespace GameLauncher.Services
|
||||
try
|
||||
{
|
||||
tg.FolderLastModified = Directory.GetLastWriteTime(tg.RootDirectory);
|
||||
cacheNeedsSave = true;
|
||||
Interlocked.Exchange(ref cacheNeedsSave, 1);
|
||||
onGameUpdated(tg);
|
||||
}
|
||||
catch { }
|
||||
@@ -933,9 +946,13 @@ namespace GameLauncher.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
|
||||
if (cacheNeedsSave)
|
||||
if (cacheNeedsSave != 0)
|
||||
{
|
||||
this.SaveCache(copyList.Where(g => Directory.Exists(g.RootDirectory)));
|
||||
}
|
||||
@@ -960,7 +977,7 @@ namespace GameLauncher.Services
|
||||
var po = new ParallelOptions
|
||||
{
|
||||
CancellationToken = ct,
|
||||
MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount * 2, 4, 16)
|
||||
MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount * 4, 8, 32)
|
||||
};
|
||||
|
||||
// 1. Everything / NTFS MFT による超高速スナップショット取得
|
||||
@@ -1020,32 +1037,37 @@ namespace GameLauncher.Services
|
||||
onLogMessage?.Invoke("標準の並列ディレクトリ走査を実行します。");
|
||||
}
|
||||
|
||||
// 全ターゲットディレクトリの直下サブディレクトリを一括集約(複数ドライブのI/Oを完全並列化)
|
||||
var allSubDirs = new List<string>();
|
||||
foreach (var targetPath in targetPaths)
|
||||
{
|
||||
if (ct.IsCancellationRequested) break;
|
||||
if (!Directory.Exists(targetPath)) continue;
|
||||
onStatusUpdated?.Invoke($"新規フォルダ走査中: {Path.GetFileName(targetPath.TrimEnd('\\', '/'))}...");
|
||||
|
||||
List<string> subDirs;
|
||||
try
|
||||
{
|
||||
if (snapshot != null && snapshot.DirectoryExists(targetPath))
|
||||
{
|
||||
subDirs = [.. snapshot.GetDirectories(targetPath)];
|
||||
allSubDirs.AddRange(snapshot.GetDirectories(targetPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
subDirs = [.. Directory.EnumerateDirectories(targetPath)];
|
||||
allSubDirs.AddRange(Directory.EnumerateDirectories(targetPath));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (allSubDirs.Count > 0)
|
||||
{
|
||||
onStatusUpdated?.Invoke($"新規フォルダ走査中 ({allSubDirs.Count} フォルダ)... (並列度 {po.MaxDegreeOfParallelism})");
|
||||
|
||||
try
|
||||
{
|
||||
Parallel.ForEach(subDirs, po, (dir, loopState) =>
|
||||
Parallel.ForEach(allSubDirs, po, (dir, loopState) =>
|
||||
{
|
||||
if (ct.IsCancellationRequested)
|
||||
{
|
||||
@@ -1118,7 +1140,6 @@ namespace GameLauncher.Services
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, ct);
|
||||
|
||||
Reference in new issue
Block a user