perf(bake): stream catalog and bound validation residency

This commit is contained in:
Erik 2026-07-24 14:05:30 +02:00
parent b7b9aaa9dd
commit 90bf6bbf45
7 changed files with 217 additions and 84 deletions

View file

@ -174,13 +174,13 @@ public sealed class PakReader : IDisposable {
}
/// <summary>
/// Validates the complete immutable artifact before an offline bake
/// publishes it. This is intentionally stricter than runtime lookup:
/// TOC order/ranges and the CRC of every unique physical blob must all be
/// valid. Aliases are checked once per shared receipt.
/// Validates the complete immutable TOC before an offline bake publishes
/// it. This is intentionally stricter than runtime lookup: key order and
/// every physical range must be valid. Blob CRC remains the reader's lazy
/// lookup tripwire; scanning a multi-gigabyte mmap here would fault the
/// whole pak into the process working set just before publication.
/// </summary>
public void ValidateComplete() {
var validatedReceipts = new HashSet<(ulong Offset, uint Length, uint Crc32)>();
public void ValidateTocStructure() {
ulong previousKey = 0;
for (int i = 0; i < _toc.Length; i++) {
@ -198,19 +198,6 @@ public sealed class PakReader : IDisposable {
$"(offset={entry.Offset}, length={entry.Length}, " +
$"file={_fileLength}, toc@{Header.TocOffset})");
}
var receipt = (entry.Offset, entry.Length, entry.Crc32);
if (!validatedReceipts.Add(receipt))
continue;
var bytes = new byte[entry.Length];
_accessor.ReadArray((long)entry.Offset, bytes, 0, (int)entry.Length);
uint actualCrc = Crc32.Compute(bytes);
if (actualCrc != entry.Crc32) {
throw new InvalidDataException(
$"pak blob 0x{entry.Key:X16} failed CRC validation: " +
$"expected 0x{entry.Crc32:X8}, got 0x{actualCrc:X8}");
}
}
}