When loading (transitively) imported AST file, ModuleManager::addModule() first checks it has the expected signature via readASTFileSignature(). The signature is part of UNHASHED_CONTROL_BLOCK, which is placed at the end of the AST file. This means that just to verify signature of an AST file, we need to skip over all top-level blocks, paging in the whole AST file from disk. This is pretty slow.
This patch moves UNHASHED_CONTROL_BLOCK to the start of the AST file, so that it can be read more efficiently. To achieve this, we use dummy signature when first emitting the unhashed control block, and then backpatch the real signature at the end of the serialization process.
This speeds up dependency scanning by over 9% and significantly reduces run-to-run variability of my benchmarks.
Depends on D158572.
uint8_t has no endianness and has alignment 1 anyway; you can just load it directly or use the same implementation as ASTFileSignature::create