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:
Dylan K. Taylor
2019-01-04 20:43:15 +00:00
parent 0bacf51729
commit 4b9a142a5d
250 changed files with 1314 additions and 45 deletions

View File

@ -30,6 +30,8 @@ use pocketmine\item\enchantment\ProtectionEnchantment;
use pocketmine\nbt\tag\IntTag;
use pocketmine\utils\Binary;
use pocketmine\utils\Color;
use function lcg_value;
use function mt_rand;
abstract class Armor extends Durable{

View File

@ -30,6 +30,7 @@ use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\tile\Banner as TileBanner;
use function assert;
class Banner extends Item{
public const TAG_BASE = TileBanner::TAG_BASE;

View File

@ -31,6 +31,8 @@ use pocketmine\event\entity\ProjectileLaunchEvent;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\Player;
use function intdiv;
use function min;
class Bow extends Tool{
public function __construct(int $meta = 0){

View File

@ -27,6 +27,9 @@ use pocketmine\block\Liquid;
use pocketmine\entity\Living;
use pocketmine\level\sound\EndermanTeleportSound;
use pocketmine\math\Vector3;
use function assert;
use function min;
use function mt_rand;
class ChorusFruit extends Food{

View File

@ -25,6 +25,8 @@ namespace pocketmine\item;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\nbt\tag\ByteTag;
use function lcg_value;
use function min;
abstract class Durable extends Item{

View File

@ -28,6 +28,7 @@ use pocketmine\block\BlockFactory;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\Player;
use function assert;
class FlintSteel extends Tool{
public function __construct(int $meta = 0){

View File

@ -43,6 +43,15 @@ use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player;
use pocketmine\utils\Binary;
use function array_map;
use function base64_decode;
use function base64_encode;
use function bin2hex;
use function file_get_contents;
use function get_class;
use function hex2bin;
use function json_decode;
use const DIRECTORY_SEPARATOR;
class Item implements ItemIds, \JsonSerializable{
public const TAG_ENCH = "ench";

View File

@ -26,6 +26,17 @@ namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\nbt\tag\CompoundTag;
use function constant;
use function defined;
use function explode;
use function get_class;
use function gettype;
use function is_numeric;
use function is_object;
use function is_string;
use function str_replace;
use function strtoupper;
use function trim;
/**
* Manages Item instance creation and registration

View File

@ -30,6 +30,7 @@ use pocketmine\entity\object\PaintingMotive;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\Player;
use function array_rand;
class PaintingItem extends Item{
public function __construct(int $meta = 0){

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use function mt_rand;
class PoisonousPotato extends Food{
public function __construct(int $meta = 0){

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use function mt_rand;
class RawChicken extends Food{
public function __construct(int $meta = 0){

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use function lcg_value;
class RottenFlesh extends Food{

View File

@ -27,6 +27,7 @@ use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\Player;
use function lcg_value;
class SpawnEgg extends Item{
public function __construct(int $meta = 0){

View File

@ -24,6 +24,9 @@ declare(strict_types=1);
namespace pocketmine\item\enchantment;
use pocketmine\event\entity\EntityDamageEvent;
use function constant;
use function defined;
use function strtoupper;
/**
* Manages enchantment type data.

View File

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item\enchantment;
use pocketmine\event\entity\EntityDamageEvent;
use function array_flip;
use function floor;
class ProtectionEnchantment extends Enchantment{
/** @var float */