mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 03:06:55 +00:00
Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called. When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace. This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified. However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement. But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations. We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
This commit is contained in:
@ -35,6 +35,17 @@ use pocketmine\Player;
|
||||
use pocketmine\tile\Spawnable;
|
||||
use pocketmine\tile\Tile;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use function array_fill;
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function chr;
|
||||
use function count;
|
||||
use function ord;
|
||||
use function pack;
|
||||
use function str_repeat;
|
||||
use function strlen;
|
||||
use function unpack;
|
||||
|
||||
class Chunk{
|
||||
|
||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\format;
|
||||
|
||||
use function str_repeat;
|
||||
|
||||
class EmptySubChunk implements SubChunkInterface{
|
||||
/** @var EmptySubChunk */
|
||||
private static $instance;
|
||||
|
@ -23,6 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\format;
|
||||
|
||||
use function assert;
|
||||
use function chr;
|
||||
use function define;
|
||||
use function defined;
|
||||
use function ord;
|
||||
use function str_repeat;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function substr_count;
|
||||
|
||||
if(!defined(__NAMESPACE__ . '\ZERO_NIBBLE_ARRAY')){
|
||||
define(__NAMESPACE__ . '\ZERO_NIBBLE_ARRAY', str_repeat("\x00", 2048));
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\BigEndianNBTStream;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function mkdir;
|
||||
|
||||
abstract class BaseLevelProvider implements LevelProvider{
|
||||
/** @var string */
|
||||
|
@ -29,6 +29,8 @@ use pocketmine\network\mcpe\protocol\BatchPacket;
|
||||
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\Server;
|
||||
use function assert;
|
||||
use function strlen;
|
||||
|
||||
class ChunkRequestTask extends AsyncTask{
|
||||
|
||||
|
@ -23,6 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\format\io;
|
||||
|
||||
use function chr;
|
||||
use function extension_loaded;
|
||||
use function ord;
|
||||
use function str_repeat;
|
||||
|
||||
if(!extension_loaded('pocketmine_chunkutils')){
|
||||
class ChunkUtils{
|
||||
|
||||
|
@ -27,6 +27,8 @@ use pocketmine\level\format\io\leveldb\LevelDB;
|
||||
use pocketmine\level\format\io\region\Anvil;
|
||||
use pocketmine\level\format\io\region\McRegion;
|
||||
use pocketmine\level\format\io\region\PMAnvil;
|
||||
use function strtolower;
|
||||
use function trim;
|
||||
|
||||
abstract class LevelProviderManager{
|
||||
protected static $providers = [];
|
||||
|
@ -33,12 +33,31 @@ use pocketmine\level\generator\GeneratorManager;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\LevelException;
|
||||
use pocketmine\nbt\LittleEndianNBTStream;
|
||||
use pocketmine\nbt\tag\{
|
||||
ByteTag, CompoundTag, FloatTag, IntTag, LongTag, StringTag
|
||||
};
|
||||
use pocketmine\nbt\tag\{ByteTag, CompoundTag, FloatTag, IntTag, LongTag, StringTag};
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use function array_values;
|
||||
use function chr;
|
||||
use function defined;
|
||||
use function explode;
|
||||
use function extension_loaded;
|
||||
use function file_exists;
|
||||
use function file_get_contents;
|
||||
use function file_put_contents;
|
||||
use function is_array;
|
||||
use function is_dir;
|
||||
use function mkdir;
|
||||
use function ord;
|
||||
use function pack;
|
||||
use function rtrim;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function time;
|
||||
use function trim;
|
||||
use function unpack;
|
||||
use const INT32_MAX;
|
||||
use const LEVELDB_ZLIB_RAW_COMPRESSION;
|
||||
|
||||
class LevelDB extends BaseLevelProvider{
|
||||
|
||||
|
@ -32,10 +32,33 @@ use pocketmine\level\generator\GeneratorManager;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\BigEndianNBTStream;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\{
|
||||
ByteArrayTag, ByteTag, CompoundTag, IntArrayTag, IntTag, ListTag, LongTag, StringTag
|
||||
};
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntArrayTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use function array_filter;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function file_exists;
|
||||
use function file_put_contents;
|
||||
use function is_dir;
|
||||
use function is_int;
|
||||
use function microtime;
|
||||
use function mkdir;
|
||||
use function pack;
|
||||
use function rename;
|
||||
use function scandir;
|
||||
use function str_repeat;
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
use function time;
|
||||
use function unpack;
|
||||
use const SCANDIR_SORT_NONE;
|
||||
|
||||
class McRegion extends BaseLevelProvider{
|
||||
|
||||
|
@ -27,6 +27,29 @@ use pocketmine\level\format\ChunkException;
|
||||
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use function array_fill;
|
||||
use function ceil;
|
||||
use function chr;
|
||||
use function fclose;
|
||||
use function fgetc;
|
||||
use function file_exists;
|
||||
use function filesize;
|
||||
use function fopen;
|
||||
use function fread;
|
||||
use function fseek;
|
||||
use function ftruncate;
|
||||
use function fwrite;
|
||||
use function is_resource;
|
||||
use function ord;
|
||||
use function pack;
|
||||
use function str_pad;
|
||||
use function stream_set_read_buffer;
|
||||
use function stream_set_write_buffer;
|
||||
use function strlen;
|
||||
use function time;
|
||||
use function touch;
|
||||
use function unpack;
|
||||
use const STR_PAD_RIGHT;
|
||||
|
||||
class RegionLoader{
|
||||
public const VERSION = 1;
|
||||
|
Reference in New Issue
Block a user