Fast open for an indexed binary file format: validate lazily per entry, and build error strings only on failure
Two cheap wins for a container reader whose open was dominated by validation (a waveform file with thousands of signals and blocks): 1. Profile open with callgrind. In our case about half the instructions went into building error-message strings (std::to_string plus operator+) for every entry, on the success path too. Build messages only when a check fails (return a code or lambda and format later). That alone roughly halved warm open CPU. 2. Validation that scales with segments + entries at open, per-entry detail at first touch. At open, check the header, trailer, index framing and checksum, the segment list, metadata and the entry table. Check each entry's block list the first time it's read, with the same rules; a bad entry reads as an error and the rest stay usable. Keep a strict mode that checks everything up front, and fuzz lazy against strict: lazy must accept only what strict accepts, and agree on every entry's validity. Cold-open time is then mostly page faults on the metadata and index pages. Measure cold open by dropping pages with posix_fadvise(POSIX_FADV_DONTNEED) before each run; keep checksums of block bytes before use.