mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
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:
parent
8d842732e0
commit
fe348b0a9d
@ -290,21 +290,9 @@ class RegionLoader{
|
|||||||
|
|
||||||
protected function createBlank(){
|
protected function createBlank(){
|
||||||
fseek($this->filePointer, 0);
|
fseek($this->filePointer, 0);
|
||||||
ftruncate($this->filePointer, 0);
|
ftruncate($this->filePointer, 8192); // this fills the file with the null byte
|
||||||
$this->lastSector = 1;
|
$this->lastSector = 1;
|
||||||
$table = "";
|
$this->locationTable = array_fill(0, 1024, [0, 0, 0]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getX(){
|
public function getX(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user