Speed up region file creation by only using ftruncate(). (#116)

* Speed up region file creation by only using ftruncate().

The old method was extremely slow (~200ms to create a single region file), but the new one is much faster (in the order of ~15ms). (Numbers were measured on a Linode 2048)

* Replace manual array fill with array_fill().

* Spaces -> tabs.

* Update RegionLoader.php
This commit is contained in:
Andrew 2016-11-23 16:23:38 -05:00 committed by Dylan K. Taylor
parent 8d842732e0
commit fe348b0a9d

View File

@ -290,21 +290,9 @@ class RegionLoader{
protected function createBlank(){
fseek($this->filePointer, 0);
ftruncate($this->filePointer, 0);
ftruncate($this->filePointer, 8192); // this fills the file with the null byte
$this->lastSector = 1;
$table = "";
for($i = 0; $i < 1024; ++$i){
$this->locationTable[$i] = [0, 0];
$table .= Binary::writeInt(0);
}
$time = time();
for($i = 0; $i < 1024; ++$i){
$this->locationTable[$i][2] = $time;
$table .= Binary::writeInt($time);
}
fwrite($this->filePointer, $table, 4096 * 2);
$this->locationTable = array_fill(0, 1024, [0, 0, 0]);
}
public function getX(){