RegionLoader: improve performance of region header validation

I was unaware that fseek actually makes a syscall which is rather costly, which became painfully obvious during large world conversions on PM4.
On average this problem appeared to be adding about 5ms to the load time for a newly loaded region, which is insanely expensive.
This commit is contained in:
Dylan K. Taylor 2021-01-20 20:04:21 +00:00
parent ea5931e274
commit ecc1e1f698
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -340,6 +340,8 @@ class RegionLoader{
/** @var int[] $usedOffsets */
$usedOffsets = [];
$fileSize = filesize($this->filePath);
if($fileSize === false) throw new AssumptionFailedError("filesize() should not return false here");
for($i = 0; $i < 1024; ++$i){
$entry = $this->locationTable[$i];
if($entry === null){
@ -352,8 +354,7 @@ class RegionLoader{
//TODO: more validity checks
fseek($this->filePointer, $fileOffset);
if(feof($this->filePointer)){
if($fileOffset >= $fileSize){
throw new CorruptedRegionException("Region file location offset x=$x,z=$z points to invalid file location $fileOffset");
}
if(isset($usedOffsets[$offset])){