mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +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(){
|
||||
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(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user