mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
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:
parent
ea5931e274
commit
ecc1e1f698
@ -340,6 +340,8 @@ class RegionLoader{
|
|||||||
/** @var int[] $usedOffsets */
|
/** @var int[] $usedOffsets */
|
||||||
$usedOffsets = [];
|
$usedOffsets = [];
|
||||||
|
|
||||||
|
$fileSize = filesize($this->filePath);
|
||||||
|
if($fileSize === false) throw new AssumptionFailedError("filesize() should not return false here");
|
||||||
for($i = 0; $i < 1024; ++$i){
|
for($i = 0; $i < 1024; ++$i){
|
||||||
$entry = $this->locationTable[$i];
|
$entry = $this->locationTable[$i];
|
||||||
if($entry === null){
|
if($entry === null){
|
||||||
@ -352,8 +354,7 @@ class RegionLoader{
|
|||||||
|
|
||||||
//TODO: more validity checks
|
//TODO: more validity checks
|
||||||
|
|
||||||
fseek($this->filePointer, $fileOffset);
|
if($fileOffset >= $fileSize){
|
||||||
if(feof($this->filePointer)){
|
|
||||||
throw new CorruptedRegionException("Region file location offset x=$x,z=$z points to invalid file location $fileOffset");
|
throw new CorruptedRegionException("Region file location offset x=$x,z=$z points to invalid file location $fileOffset");
|
||||||
}
|
}
|
||||||
if(isset($usedOffsets[$offset])){
|
if(isset($usedOffsets[$offset])){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user