A one-megabyte buffer that made loading 294x slower
Loading a 4000m map took 238 seconds. That is long enough that I assumed it was the parsing, so I spent an evening optimising the protobuf reader, and got it down to about 230. Not the parser, then.
It was the FileStream. Prefab data is thousands of small reads scattered across the file, and every one of those seeks was landing inside a 1MB buffer that had to be refilled from disk. The buffer was doing exactly what buffers are for, and it was the reason the whole thing crawled: each 40-byte read pulled a megabyte off disk and threw away all but the part it wanted.
Unbuffered, the same load is 63 seconds. The fix is one constructor argument. Finding it meant actually measuring instead of guessing at the slow part, which I had already been wrong about once.